I've created a service using srvany which starts a little prog I wrote to monitor for a "switch user" condition and then on recognising one, kicks off a batch file which starts an ftp synchronisation.

The service is set to autostart and I've added Spooler as a dependency.

The problem is that after a reboot, although the service shows running, nothing happens when I switch user. If I stop and start the service, then switch user (the trigger) - everything works perfectly - and continues to work perfectly until the PC is rebooted again.

I can't understand why it's necessary to stop/start the service after a reboot.

Any ideas/suggestions gratefully received!

Cheers

Dani AI

Generated

The behaviour describes — the service is shown as "running" after boot but only works after a manual stop/start (as noted when you start it manually) — strongly suggests a startup-time or session-context problem rather than a logic bug in the trigger itself. Typical root causes are: the service process is running in a different session/account than the interactive user, required desktop/session resources are not available at the moment the service first starts, or the program fails to register for the switch-user notification at boot and silently exits or ignores errors.

Quick diagnostic checklist you can do now:

  • Add robust startup logging to the monitor (timestamp, return codes when registering for notifications, any last error) so you can compare boot vs manual-start behavior.
  • Check Event Viewer for service or application errors produced at boot.
  • Inspect the running process after boot with Process Explorer / Task Manager to confirm the account and Session ID it uses; compare that to the process after manual restart.

Two practical fixes, depending on what diagnostics show:

  • If the monitor needs to run in the interactive user session (so it can receive per-user UI messages), run it as a per-user agent (Startup folder, Run registry key, Group Policy logon script, or a Scheduled Task that runs at user logon) rather than as a system service.
  • If you must keep a service, have the service spawn a helper in each interactive session using the documented Windows APIs (obtain the user token with WTSQueryUserToken and create the process with CreateProcessAsUser). That keeps the central service privileged but runs the session-sensitive watcher where it can actually see session changes.

Relevant Microsoft references: session‑0 isolation background and guidance (), and APIs for launching processes in a user session (WTSQueryUserToken, CreateProcessAsUser).

Recommended Answers

All 2 Replies

Just a guess. Does it work if you switch the service's Startup Type to 'Manual' ?

Thanks for your suggestion. It would work if I manually started the service (as it does when I restart it) but I really need this to kick in automatically - and there's no other trigger to start the service.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.