【问题标题】:Shutdown or Restart Computer from WCF Service Not Working从 WCF 服务关闭或重新启动计算机不起作用
【发布时间】:2016-02-26 11:46:55
【问题描述】:

我在 IIS 7.5 中托管的 WCF 服务中有一个函数,它的任务是在调用它时关闭或重新启动计算机。

我使用内置命令行并通过传递“shutdown.exe -t 0 -r”来重新启动或“shutdown.exe -t 0 -s”来关闭来执行它。

    Try
        Using process As New System.Diagnostics.Process()
            Dim startInfo As New System.Diagnostics.ProcessStartInfo()
            With startInfo
                .WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
                .CreateNoWindow = True
                .UseShellExecute = False
                .RedirectStandardError = True
                .RedirectStandardInput = True
                .RedirectStandardOutput = True
                .FileName = "shutdown.exe"
                .Arguments = "-t 0 -r"
            End With
            If System.Environment.OSVersion.Version.Major >= 6 Then process.StartInfo.Verb = "runas"
            process.StartInfo = startInfo
            process.Start()
            process.WaitForExit()
            If process.ExitCode = 0 Then
                Return True
            Else
                Return False
            End If
        End Using
    Catch ex As Exception
        Return False
    End Try

如果在命令提示符下手动执行,命令行可以正常工作。但是在 WCF 服务中执行时它不起作用。

【问题讨论】:

  • WCF 服务以什么身份运行?您可能还想将-f 添加到参数中。
  • wcf 应用程序池作为本地系统运行。 -f 参数是什么?
  • 强制关闭正在运行的应用程序:technet.microsoft.com/en-us/library/bb491003.aspx
  • @slugster 它仍然不起作用。我认为通过使用本地系统身份,我们将拥有所有管理员权限。但它似乎不是它的工作原理。

标签: wcf acl wcfserviceclient


【解决方案1】:

好的,尝试一切并保持失败,并以this guy who use bat file 结束。它有效..!

这太奇怪了,仍然不知道它为什么会起作用。现在...谁在乎 :)...以后有空我会想办法解决的。

        ....
        Dim strCmd As String = "SHUTDOWN -m {0} -f -t 0 -r"           
        File.WriteAllText(_pathCmd & "cmd_restart.bat", String.Format(strCmd, "127.0.0.1"))
        Return ExecuteCommand(_pathCmd & "cmd_restart.bat", "")

【讨论】:

    【解决方案2】:

    我猜你的服务没有权限关闭电脑(我猜欠权限的用户是网络用户,不能这样做)。 Check out Event Log for details,我很确定它包含您问题的答案。

    查看there如何在特定账户下运行wcf服务。

    【讨论】:

    • 我尝试通过提供特定的管理员凭据来运行该进程。然后我得到 4 个新事件日志: 1. 尝试使用显式凭据登录。 2. 一个账号成功登录。 3.分配给新登录的特殊权限。 4. 一个账号被注销了。
    • 但是什么也没发生。不重启,不关机。什么都没有。
    猜你喜欢
    • 2013-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    • 2012-01-23
    相关资源
    最近更新 更多