Automatically executing start-up actions and locking workstation
Note: this entry has moved.
I came across the need to ensure that upon machine startup, certain programs in the
Start group get executed even if I'm not around to logon with my session. This is typically
the case if you have your webserver in your machine and want to automatically connect to the
Internet and update a dynamic DNS service with the new IP. You could use
SrvAny to make those
apps look like services that would run without the need to logon. But most applications store
settings in user-specific folders, and will not work without an initiated session.
Microsoft
offers a "solution" to you: enable automatic logon. Ups. It works in Windows 2003 too. But now the problem is that the machine will remain
logged-on until your password-protected screen saver comes up to lock the workstation. I'm using the following
script, which gives the startup programs enough time to do their work and then automatically blocks the session:
<package>
<job id="lock">
<script language="JScript">
var WshShell = WScript.CreateObject("WScript.Shell");
// 5 minutes are enough for me ;)
WScript.Sleep(300000);
WshShell.Exec("rundll32 user32.dll,LockWorkStation");
</script>
</job>
</package>
This script is a .wsf file executed by Windows Script Host. We want to ensure this script is ALWAYS
run. You know that pressing Shift
at windows start skips executing the Start group. To avoid
that we can make this script be run though the registry:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"LockStation"="C:\\LockStation.wsf"