Start a windows service and launch cmd

后端 未结 4 990
一整个雨季
一整个雨季 2020-11-29 04:20

Do I need to enable Interactive desktp for it to work and what is the correct code to start an EXE or cmd window? I\'m still unable to start the service even when I had enab

4条回答
  •  一个人的身影
    2020-11-29 04:40

    When running as a service you won't be able to launch anything that needs to interact with the desktop OR will spawn it's own windows.

    As Aliostad said, you need to call Win API calls to CreateProcessAsUser and emulate the user in order with this to work. This involves emulating the logged in user and using their credentials to "lift" your process into process isolation level 1 (which gives you access to the windowing system and things like the GPU).

    I am doing this in an app I wrote and it does work but I agree with Aliostad there is a bit of Black magic going on and it generally sucks

    Having said all that, you can spawn worker processes from within a service as along as they don't require things that are in process isolation level 1 (Windowing, GPU etc..)

    cmd.exe by default will try to create a window, this is why your example is failing. You could set the following ProcessStartInfo properties to get it work.

    CreateNoWindow WindowStyle

提交回复
热议问题