Starting a Windows service in an interactive session

33,656

Solution 1

In case "Interact with desktop" on the service is not enough (I have seen a handful of cases where it is not), you can combine it with AutoAdminLogon. Create three (or four for a domain) REG_SZ values under HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon:

  • DefaultUsername
  • DefaultPassword
  • DefaultDomain
  • AutoAdminLogon

AutoAdminLogon should be set to the string "1", the others are self-explanatory.

Obviously this has security issues big enough to fly Jupiter through.

Solution 2

Have you tried having your script run as a Windows service, but allowing it to interact with the desktop?

Specifically:

  1. Go to the service properties page
  2. Click on the "Log On" tab
  3. Select "Local System account"
  4. Check "Allow service to interact with desktop"

Solution 3

See my similar question and real answer to it: How to start a process from windows service into currently logged in user's session NOTE: "Interact with desktop" checkbox is not enough at all.

Share:
33,656
Plutor
Author by

Plutor

Updated on July 20, 2020

Comments

  • Plutor
    Plutor almost 4 years

    A colleague has a batch script program which needs to to run on a Windows Server in console mode, so that it has access to a Windows interactive session. The server is rebooted at regular intervals automatically (there's an unrelated closed-source application that runs on this machine that we have no control over). After a reboot he wants to automatically start a Windows interactive session and have this script run, plus the service needs to also have access to network resources (CIFS drives, in particular).

    Here's what we've tried so far:

    1. Start as Windows service. This failed, since a Windows service can either have access to interactive session or to network resources, but never both.
    2. Used Microsoft management console to add the script to run at startup, however this did not work.
    3. Used an HKLM registry key to start to run this script, however it only gets started when we manually open a remote desktop session on the server.
    4. Creating a scheduled task. The program invoked did not have access to interactive windows session.

    Any other suggestions? (Or maybe he missed something when he set up one of these suggestions?)

  • Plutor
    Plutor almost 15 years
    He already tried this. Unfortunately, logging into a Local System account prevents the script from accessing network resources, which we need to be able to do. (I'll update the question to reflect this.)
  • Plutor
    Plutor almost 15 years
    This ended up being the solution. We had tried the HKLM entry before, but not with AutoAdminLogin set. It's a security issue, but since they are behind-the-firewall server farm machines, it's not really a significant one.
  • school_guy
    school_guy almost 6 years
    @JimG Cool solution, but can we achieve this without writing the password in clear text?
  • DaFox
    DaFox over 3 years
    Thank you for being the only one to bring this up in the various answers to this question. We're going with this route for some automated testing servers. We had our agent instance running as a service but ended up hitting blocking issues with our target application needing complex desktop interaction... Can't believe this was so difficult!
  • DaFox
    DaFox over 3 years
    Microsoft Documentation on this: docs.microsoft.com/en-us/troubleshoot/windows-server/… > You can use the Sysinternals tool AutoLogon to enable this functionality easier. This tool also helps you to use an encrypted version of password.
  • DaFox
    DaFox over 3 years
    I had to set DefaultDomainName as well. I set it to our short domain name, and Set DefaultDomain to our FQDN.