【发布时间】: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