Run Batch-Files in Windows Service while logged off

♀尐吖头ヾ 提交于 2019-12-12 05:25:39

问题


I wrote a windows service in C# .NET 3.5. It starts up automatically and runs as Local System User (no log in required).

If i run a Shutdown-Batch-File (shutdown -s -t 30) with my service by calling Process.Start(), nothing happens until i log in to windows. So it waits for logging in and then starts the batch.

Is it possible to run this batch in logged off state?

Greetings


回答1:


There is a property for each service application called Allow Interact With Desktop that should be set True for your service to be able to run Shutdown-Batch-File.

Take a look at these links:

Interact With Desktop when Installing Windows Service

Allow service to interact with desktop in C#




回答2:


Have you checked to make sure this is not a permission issue? Ie does it work if the service is running as an administrator?

You might also want to try the alternative methods of shutting down mentioned in this question how-to-shutdown-the-computer-from-c#.



来源:https://stackoverflow.com/questions/5975291/run-batch-files-in-windows-service-while-logged-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!