简体   繁体   English

从.NET Windows服务启动进程

[英]starting a process from a .NET windows service

I am trying to start a console application from a .NET Windows Service. 我试图从.NET Windows服务启动一个控制台应用程序。 The service is running on a Windows 2008 server. 该服务正在Windows 2008服务器上运行。

I use Process.Start to run the console application and it runs( I can see it in the task mgr), but I never get the process id back and the call to Process.Start just hangs. 我使用Process.Start运行控制台应用程序并运行(我可以在任务mgr中看到它),但我从来没有得到进程ID,并且对Process.Start的调用只是挂起。 If I run the same service from my Windows 7 machine the process runs and I get the process Id back no problem. 如果我从我的Windows 7机器运行相同的服务,该过程运行,我得到进程ID回来没问题。

I am confused .. 我很困惑 ..

I had exactly this same problem. 我有同样的问题。 For me the key was to set StartInfo.UseShellExecute = false; 对我来说,关键是设置StartInfo.UseShellExecute = false;

Is it possible that the process you are spawning is attempting to prompt the window station for user input? 您正在产生的进程是否可能尝试提示窗口站进行用户输入? In which case it could hang... 在这种情况下它可能会挂起......

Which process are you starting? 你从哪个过程开始? Is it part of the platform/OS (like cmd.exe) or something custom? 它是平台/操作系统(如cmd.exe)的一部分还是自定义的?

After a long time search for a solution for this, I found the wise stones for my problem. 经过很长一段时间寻找解决方案,我找到了解决问题的明智之举。

I made a new WindowsForm based program, with same Process.Start command, and then the standard "Windows Warning Security" dialog box shows up, and thats why it dosent work. 我使用相同的Process.Start命令创建了一个基于WindowsForm的新程序,然后显示标准的“Windows警告安全性”对话框,这就是为什么它起作用了。

After turn off "User Access Control" the Windows Service works correctly. 关闭“用户访问控制”后,Windows服务正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM