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"

1 Comment

  • If you want to run it as a service, and the program requires access to user data, do this:



    --&gt; Create an accunt &amp; grant it log on as service rights

    --&gt; Logon to the account interactively, run the program &amp; configure as you like

    --&gt; Logoff &amp; log back on as an admin

    --&gt; Install the service with srvany

    --&gt; Configure the service to run under the account you created in the services CP (start&gt;run&gt;services.msc)

Comments have been disabled for this content.