【问题标题】:Run Batch-Files in Windows Service while logged off注销时在 Windows 服务中运行批处理文件
【发布时间】:2011-08-23 22:26:32
【问题描述】:

我在 C# .NET 3.5 中编写了一个 Windows 服务。 它会自动启动并以本地系统用户身份运行(无需登录)。

如果我通过调用 Process.Start() 使用我的服务运行 Shutdown-Batch-File (shutdown -s -t 30),则在我登录 Windows 之前不会发生任何事情。所以它等待登录,然后开始批处理。

是否可以在注销状态下运行此批处理?

问候

【问题讨论】:

    标签: c# .net .net-3.5 windows-services


    【解决方案1】:

    每个服务应用程序都有一个名为Allow Interact With Desktop 的属性,应将其设置为True,以便您的服务能够运行Shutdown-Batch-File

    看看这些链接:

    Interact With Desktop when Installing Windows Service

    Allow service to interact with desktop in C#

    【讨论】:

    • 感谢您的回答。我已将其设置为 true。但什么也没发生:(
    • codeproject.com/KB/system/xyntservice.aspx 和你想要的很相似。
    • 我明白了!是防火墙-.-(我正在从路由器外部测试注销模式):D 感谢您的帮助!
    【解决方案2】:

    您是否检查过以确保这不是权限问题?即服务是否以管理员身份运行?

    您可能还想尝试此问题how-to-shutdown-the-computer-from-c# 中提到的其他关闭方法。

    【讨论】:

    • 是的,我已经检查过了。 (通过使用管理员)可能在注销时无法启动批处理?看来批处理只会排队等待登录。我会尝试通过直接shutdown.exe-call关闭您的替代方法,谢谢。还有其他人有想法吗??
    猜你喜欢
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多