How do I start something after Windows logon is complete?

I have a system service running on my Windows machine that can impersonate a logged in user and run applications on their behalf (including UI applications).

It works great when the user is already logged into their interactive session, the desktop is created, etc.

The service starts automatically, so it starts automatically after every reboot. If it tries to start some program (which requires access to the user interface) immediately after starting the service, that program might crash - possibly because the autologon process is still in progress, the Desktop hasn't been created yet, etc.

Question: If the service starts "early", how can it fully initialize the interactive session (other than waiting for some arbitrary time, which is not optimal)?

Or is it possible to start the service "late"? Is there a registry key or folder, or something else that I can use to delay the start of the service until the shell is ready and the UI applications start safely?

+3


source to share


1 answer


The easiest two ways to "execute some code when the user logs in" is to write a .bat file and either:

1) Place the .bat file in your Startup folder <= Note: Windows 7 / Vista has a new location for the Startup folder

... or...

2) Create a new task that calls the .bat file on login



Option "2" "gives you finer control. It also allows you to use the .bat file" Run as administrator "if needed.

If you want to temporarily pause the .bat file (for example, to make sure everything is fully initialized), you can add "ping -w" to your .bat file.

Example:

@rem Waits 5 seconds before continuing
ping 1.1.1.1 -n 1 -w 5000 > nul

      

+2


source







All Articles