Auto-Login Windows XP/Win-7 using a Batch File (or VB Script) stored in a Standard USB Pen Drive
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?
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
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.