问题
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