Starting a Windows service in an interactive session

后端 未结 5 2062
时光说笑
时光说笑 2020-12-05 08:42

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 reboo

相关标签:
5条回答
  • 2020-12-05 09:09

    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"
    0 讨论(0)
  • 2020-12-05 09:22

    I had to do something similar recently; a route that I found but discarded due to security concerns is to have the interactive service set self as running in interactive mode and then run the ImpersonateUser function in the win32 API, which I think will provide the benefits of both a user and the interactive session available from the LocalSystem.

    Needless to say, if someone broke into a service that did that, they would have total control of the machine.

    0 讨论(0)
  • 2020-12-05 09:23

    I recommend going about this another way. You could build another Windows app that communicates via IPC to the Windows Service and that could be what deals with the closed souorce application. But if you must, you can specify an option in the service (you can do this through MMC, registry, etc). Basically, you can see this option by going to Computer Management->Services and Applications->Services->Right click your service->Change account to Local System and check "Allow system to interact with desktop."

    However, again, I recommend choosing another path.

    0 讨论(0)
  • 2020-12-05 09:24

    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.

    0 讨论(0)
  • 2020-12-05 09:29

    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.

    0 讨论(0)
提交回复
热议问题