简体   繁体   English

在Win7和Win8而不是Windows 2012 R2下可运行的Process.Start()

[英]Process.Start() working under Win7 and Win8 but not Windows 2012 R2

My program, run via a Windows Service was able to successfully run the following code under Win7 and Win8. 通过Windows服务运行的我的程序能够在Win7和Win8下成功运行以下代码。

Log("About to run the file...");
try
{
    Process.Start(filePath, args);
    Log("File Triggered!");
}
catch (Exception ex)
{
    Log("Error.");
}

Although the UI of the program located at filePath was never shown, but the program did its job completely in the background. 尽管从未显示过位于filePath的程序的UI ,但是该程序完全在后台执行其工作。

When I try the exact same program on a Windows 2012 R2 environment, I notice that after receiving the first log message above in my log file ("About to run the file...") nothing else is logged and Process.Start() does not work either. 当我在Windows 2012 R2环境中尝试完全相同的程序时,我注意到在我的日志文件(“关于要运行该文件...”)中收到上述第一条日志消息后,没有其他记录,并且Process.Start()也不起作用。 This is confusing because the exact same program worked in other operating systems. 这是令人困惑的,因为完全相同的程序可以在其他操作系统中使用。

So if Process.Start() is not called successfully, who do I not receive the "Error" message in my log and if Process.Start() is run, why do I not get the "File Triggered!" 因此,如果未成功调用Process.Start() ,谁没有在我的日志中收到“错误”消息,并且如果运行了Process.Start() ,为什么我没有得到“文件触发”信息呢? message? 信息?

Update: Following the comments, I ran Process Monitor and this is the log generated for the target .exe file at the exact minute that it was supposed to run. 更新:根据评论,我运行了进程监视器,这是在目标.exe文件应该运行的确切分钟生成的日志。 Please take a look and see you find anything suspicious: 请看看,发现有任何可疑的地方:

Link to log spreadsheet on Google Docs 链接到Google Docs上的日志电子表格

I think this is because Windows Server 2012 does not by default allow processes to run interactively. 我认为这是因为Windows Server 2012默认情况下不允许进程以交互方式运行。

See here for details. 有关详细信息,请参见此处。

You can override this behaviour by setting a registry key: 您可以通过设置注册表项来覆盖此行为:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows
NoInteractiveServices

Set the value to "0". 将该值设置为“ 0”。

  1. What's in process viewer -- do you see your process to start? 进程查看器中有什么功能-您看到进程开始了吗?
  2. What's in Windows Event Log? Windows事件日志中有什么?
  3. Win2012 is probably more strict regarding security and your application (executed from service, thus quite specific user). Win2012在安全性和应用程序(从服务执行,因此非常特定的用户)方面可能更加严格。 You can try using FileMon/ProcessMonitor from SysInternals to check which call it is failing at or stuck at. 您可以尝试使用SysInternals的FileMon / ProcessMonitor来检查失败或卡在哪个调用。

And a generic advice: starting UI from service in Windows is not the best practice. 一条通用建议:从Windows中的服务启动UI并非最佳实践。 Services are created to do some background work and not to have user interaction. 创建服务是为了进行一些后台工作,并且没有用户交互。 If you need UI for your service, better create UI that user start himself, of create a small app that will sit in tray and wait for an event from service and then start UI in user so called "window station". 如果您需要用于服务的UI,则最好创建用户自己启动的UI,或者创建一个小应用程序,该应用程序将坐在托盘中并等待服务中的事件,然后在用户(称为“窗口站”)中启动UI。

Windows Server 2012 blocks all the files copied from other places. Windows Server 2012会阻止从其他位置复制的所有文件。 So I unblocked all the program files. 因此,我解除了所有程序文件的阻止。 Thanks for your help. 谢谢你的帮助。

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

相关问题 附加到VS2012中的Win8进程 - Attach to a win8 process in VS2012 控制台应用程序的 Process.Start() 无法从 Server 2008 R2 中的 Windows 服务工作 - Process.Start() of a console app not working from Windows Service in Server 2008 R2 DirectX 应用程序无法通过 Process.Start 在 Windows Server 2012 R2 上加载,通过 CMD 或在本地计算机上正常工作 - DirectX app unable to load through Process.Start on Windows Server 2012 R2, works fine through CMD or on local machine 图像渲染Win8 / Win10但不是Win7 - Image Renders in Win8/Win10 but not Win7 Windows服务Process.Start不在网络服务帐户下工作 - Windows service Process.Start not working under network service account Process.Start 在 Windows XP 机器上抛出 Win32 异常访问被拒绝 - Process.Start throws Win32 Exception Access is Denied on Windows XP Machines Tcp客户端无法在WIN8上断开连接,但在WIN7上完全断开连接 - Tcp clients could not disconnect on WIN8 but disconnect perfectly on WIN7 如何在Win7和Win8上访问存储的凭据(PasswordVault?)? - How to access the stored credentials (PasswordVault?) on Win7 and Win8? Process.Start无法在Windows Server 2008 R2上打开URL - Process.Start doesn't open URL on Windows Server 2008 R2 process.Start 在按钮按下时导致 Win32Exception - process.Start causing Win32Exception on button push
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM