注销时在 Windows 服务中运行批处理文件
我用 C# .NET 3.5 编写了一个 Windows 服务。 它会自动启动并以本地系统用户身份运行(无需登录)。
如果我通过调用 Process.Start() 使用我的服务运行 Shutdown-Batch-File (shutdown -s -t 30),则在我登录 Windows 之前不会发生任何情况。因此它等待登录然后开始批处理。
是否可以在注销状态下运行此批处理?
问候
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个服务应用程序都有一个名为
允许与桌面交互
的属性,应将其设置为True
,以便您的服务能够运行Shutdown-Batch-File
代码>.查看这些链接:
安装 Windows 服务时与桌面交互
C# 中允许服务与桌面交互
There is a property for each service application called
Allow Interact With Desktop
that should be setTrue
for your service to be able to runShutdown-Batch-File
.Take a look at these links:
Interact With Desktop when Installing Windows Service
Allow service to interact with desktop in C#
您是否检查过以确保这不是权限问题?即,如果该服务以管理员身份运行,它可以工作吗?
您可能还想尝试此问题中提到的其他关闭方法 how-从-c# 关闭计算机。
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#.