10

Why I need this:

I have Pen Drive full of batch scrips and other diagnostic tools. I have 75 stand-alone (Not Networked) PCs 'mostly with Win-XP-Pro SP-2, in 2 Labs. I often need to login each PC with admin account to configure or diagnose something.

So when i start a PC, each time i have to manually select the user name from log-in screen and also type its password.

Now i want to Login to Admin Acc. Automatically (programmatically) if my pen drive is connected to the PC.

What i Know:

I know it is possible to run Scripts (Batch Files) before user login in XP/Win7. I wrote a batch file and saved to local PC. I configured it in group policy to run it on system startup (GPO Location: Computer Configuration\Windows Settings\Scripts (Startup/Shutdown)\Sartup). This batch file successfully detecting 'if the pen drive is connected or not.

I have another batch file (currently blank) stored on Pen Drive.

The 1st batch file searches all drives from C to Z for 2nd (login.bat) batch file using a loop, if the file is present it assumes pen drive is present and further calls the 2nd (login.bat) batch file to proceed.

What i don't Know:

Now I don't know what should be the code of login.bat file or i don't know 'how to login pragmatically.

What are other alternatives in mind:

It is not necessary to use a batch file only. I can also consider 'if you have any other option for auto login like using VB Script or any other 3rd part executable',

Edit:

According to this question Set user for auto logon on windows via batch script I can create a script to modify registry entries and allow auto log on. Even though this works, you have to reboot your PC for the changes to be applied. Which is something I want to avoid. It takes more time to run the script and reboot than just logging in personally.

I would like to be able to log on automatically, on demand. This means that once I connect my Pen Drive, the script should be able to log me in, in the admin account without rebooting the PC.

I read on the web it can be achieved by creating a GINA dll file, but I have no experience on that field. Any ideas how this can be implemented?

| |
  • 1
    Possible duplicate of Set user for auto logon on windows via batch script – Jimmy_A Aug 8 '17 at 10:52
  • @D.A-How can you say it is duplicate of "Set user for auto logon...".? Did you read the complete explanation of the question? And do you know what is mean by "Setting a user for Auto Login. This is not the duplicate of one specified by you. I don't want to Set a user for auto login each time turn on the PC. This will enable the user to login automatically regardless the Pen Drive is attached or not. I need a batch file or vbscript file to initiate the login 'Only if my pen drive is attached to the PC. Read the complete question carefully. – Ajaib Singh Aug 9 '17 at 3:54
  • @D.A Sir i carefully read the specified answer. Even internet is full with this tutorial. 1st' it does not Check the presence of Pen Drive to conditionally allow the Auto-Login. 2nd' As you highlighted the "Set how many times it should log on" option. It is not suitable for me. Let me explain why. I have only 2 possible values that can be assigned to "Set how many times it should log on". 1st is 1 and 2nd is 'greater than one' – Ajaib Singh Aug 9 '17 at 9:02
  • If i set it as 1: It will only allow auto-login once. On next start-ups 'I have to enter user name and password. If i set it greater then 1 (Say 10) it will auto login specified number of times. Now until the specified number of times is expired 'every user will get logged-in to admin account by default. Which i don't want. My requirement is: "Allow Infinite number of Logins" as long as my pen drive is connected else don't allow auto-login. – Ajaib Singh Aug 9 '17 at 9:02
  • 2
    Questions: (1) Do you have only one logon for all computers with same user/password? (2) Can you install a software solution (if it exists) on all the computers? (3) Would you pay for a commercial product? – harrymc Aug 10 '17 at 14:32
2
+25

It is possible to login programmatically to Windows, but not with a simple batch file. Instead you need to build a DLL using C++ (or maybe C# - but it's not recommended). In Windows XP (and before), this facility is called GINA.
(Starting from Vista you need to build a Credential Provider.)

Reference: Login to windows xp programatically

| |
  • Hi wp78de"; I have solved my problem with VB Script. Which just send Keys on login screen, and My admin account get loged in. Thanks for the answer. – Ajaib Singh Aug 19 '17 at 5:13
1

I accidentally found the solution by myself. As mentioned in question i have 2 scripts: 1st resides in local computer and 2nd resides in Pen Drive. 1st (.bat) is preconfigured to run on system startup (See how to assign computer startup scripts?) and it calls 2nd (.vbs) if pen drive is connected.

How it works:

The working of 1st file is already described in Question; and working of 2nd script is very simple but fulfills my needs. This script just sends key strokes on login screen in same sequence as i type on keyboard for Login. Here i would like to share the whole code of both scripts. Hope this will help many like me, who don't want to interfere with internal operating system files such as GINA.

The code is:

1st Script (Logon Script)

Name: "Find PD.bat"

Location:

"%SYSTEMROOT%\System32\GroupPolicy\Machine\Scripts\Startup\Find PD.bat"

Code

@ECHO OFF
SET vCount=1
set LogFl=%~d0%~p0%Find PD.log
echo Process Started...>"%LogFl%"

:RECHK
SET PD=
for %%i in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
    IF EXIST "%%i:\OTHER\RESTORE\OTHER\FillCred.vbs" (
        SET PD=%%i
    )
)

:FOUND
echo:>>"%LogFl%"
IF /I DEFINED PD (
    echo %time% : Pen Drive Found with '%PD%' Drive Letter>>"%LogFl%"
    "%PD%:\OTHER\RESTORE\OTHER\FillCred.vbs"
) ELSE (
    IF %vCount% LSS 11 (
        set /a "vCount=vCount+1"
        echo %time% : Retry: %vCount% >>"%LogFl%"
        ping -n 2 -w 200  1.1.1.1>nul
        GOTO RECHK
    ) ELSE (
        echo %time% : Pen Drive Not Found. Exiting>>"%LogFl%"
        EXIT /b 1
    ) 
)
:EOF

2nd Script:

Name: "FillCred.vbs"

Location:

"<PenDriveRoot>\OTHER\RESTORE\OTHER\FillCred.vbs"

Code:

set WshShell = CreateObject("WScript.Shell")
WScript.sleep 1000
WshShell.SendKeys "{DOWN}"
WScript.sleep 50
WshShell.SendKeys "ReplaceThisWithYourPassword"
WScript.sleep 50
WshShell.SendKeys "{ENTER}"

Remember:

1) This is only tested on windows XP.

2) This will only work if your Windows shows default logon screen (aka 'Welcome Screen')

3) You have to modify 2nd script for your key sequences.

4) This will not work if your system require pressing Ctrl+Alt+Delete before login.

5) This is very basic solution, but you may make it advanced by editing the 2nd Script. this will work as long as you system allows key strokes on login screen.

Thanks.

| |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.