Reputation: 87
Here's the situation: I've got .bat file that is being started by windows scheduler every 15 min. However, when system logs off user - actions are not being performed. I'd like to know, if it is possible to add some code to .bat file to make it log in to system again ?
Upvotes: 1
Views: 14778
Reputation: 15920
When the user logs out, if the screen goes to a CTRL+ALT+DEL login screen, good-luck-chuck. No one has found a way to force windows to recognize CTRL+ALT+DEL from any programming language. Not even VBScript SENDKEYS will do it. However, if it goes directly to the user login to enter the name and password you can create a small .vbs sendkeys script to auto-login the user prior to running your .bat:
login.vbs
set wshShell = WScript.CreateObject("WSCript.shell")
wshShell.sendkeys "Username"
wscript.sleep 1000
wshShell.sendkeys "{Tab}"
wscript.sleep 1000
wshShell.sendkeys "Password"
wscript.sleep 1000
wshShell.sendkeys "{ENTER}"
WScript.Quit
Throw it into windows scheduler to run even if user is logged off. Or better yet, if you want to have it auto-login the user say 15 minutes after they log out, you can add it to the local Group Policy for that machine:
In RUN type gpedit.msc navigate to Local Computer Policy -> User Configuration -> Windows Settings -> Scripts (Logon/Logoff) Double click on Logoff and hit Add... In script name, enter the path of your .vbs and hit ok. At the beginning of the .vbs file, add
wscript.sleep 900000
That will force it to wait 15 minutes before running the rest of the script automatically when a user logs off.
Upvotes: 1
Reputation: 3192
There is an option in the Tasksheduler wheter to run the task too if the user is logged off. Activate that and it should work fine.
Upvotes: 1