我的 Process.Start() 实现在 Windows 2012 R2 中不起作用
我在我的 Windows 2012 服务器上部署了 Windows 服务。在 Windows 服务中,我尝试使用 Process.Start(fileName) 调用一个批处理 (.bat) 文件。
运行服务时无法调用批处理文件。
我做了一些更改,例如将 NoInteractiveServices 设置为 0 并取消阻止所有文件......但运气不好..
谁有不同的解决方案??
Private Function RunTask(ByVal sPath As String, ByVal sArgs As String, ByVal fLog As Boolean) As Boolean
Dim targetProcess As Process
Try
targetProcess = Process.Start(sPath, sArgs)
Catch ex As Exception
WriteToLog("Can not start process '" + sPath + "' - " + ex.Message)
Return False
End Try
If fLog = True Then
WriteToLog("Started process '" + sPath + "' with args '" + sArgs + "'")
End If
Return True
End Function
它调用批处理文件,然后继续下面的代码:
--> net stop "Exstream Monitor"
最佳答案
deployed windows service on windows 2012 server ... process.start(bat file name).
- 服务进程是否有权访问相关文件?
- 是否将
CreateNoWindow
的属性设置为true
并将UseShellExecute
的属性设置为false
? - 服务代码是否捕获所有异常并将该信息发送到日志或系统事件?
- 代码避免了 GUI 弹出窗口或任何/所有 GUI 相关任务?
- bat 文件是否可以手动运行并正常运行,还是默默地失败?
关于.net - Process.Start() 不适用于 Windows 2012 R2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37850187/