错误代码 0xc0000142 从 windows 服务启动进程
Error Code 0xc0000142 starting process from windows service
从 Windows 服务启动进程时出现问题
_________
| | * Process 1
| Service | -------> * Process ...
|_________| * Process n
服务使用的代码如下:
ProcessStartInfo startInfo = new ProcessStartInfo(executablePath, commandlineArgs);
startInfo.WorkingDirectory = instancePath;
startInfo.UserName = userB;
startInfo.Password = passwordSecureString;
startInfo.Domain = domain;
startInfo.UseShellExecute = false;
Process process = new Process
{
StartInfo = startInfo,
EnableRaisingEvents = true,
};
process.Start();
现在,我有两个帐户 - 为简单起见,假设为 A 和 B。服务在第一个帐户下 运行,并使用第二个帐户启动进程。
- 两个帐户都在本地管理员组中
- 两个账户都有权作为服务登录
- 已启用二次登录服务(以防万一,应该有关系)
- OS: Windows 服务器 2012 R2.
下面的table应该表示在哪个帐户星座中发生的事情。
_______________
| | A | B |
|===+=====+=====|
| A | OK | X |
|---+-----+-----|
| B | X | OK |
|___|_____|_____|
- 确定 - 进程按预期启动
- X - 服务没有错误,但进程立即终止。
...这让我假设用户更改导致了问题。
发生异常的详细信息:
在阅读了错误代码 142 之后,这是我目前所做的尝试:
- 不同的服务器
- Windows 更新
- Redistributable c++ 安装
- 咖啡,接着是烈酒,然后是咖啡
任何人都可以解决这个问题吗?
Stephen Martin 已经解释了这里发生的事情,所以如果您遇到原始问题中描述的问题,您可能会对以下博客 post 感兴趣:
http://asprosys.blogspot.de/2009/03/perils-and-pitfalls-of-launching.html
在这里,斯蒂芬解释说
Oops again, where is the process? Check the event log (or you may have received an Application Error pop-up). There should be an entry for Application Error that says that your process was the faulting application, either user32.dll or kernel32.dll was the faulting module and the exception was: 0xC0000142. There may be some minor variation in this but basically it is saying that your application could not initialize. The reason for this is that on initialization, before any application code is run, all processes are attached to a Window Station and all threads are attached to a Desktop but the user you are launching under does not have permission to access the Window Station and Desktop in which your process is being launched, ergo it can't initialize. The security descriptors for the Window Station and Desktop must be adjusted to give AllAccess permission to the user the process is being launched under. This is a devil to do directly in .Net, so you might find the security wrapper classes here useful
如果您不喜欢使用 Stephen 的库,您还可以查看提供的其他解决方案here(我还没有测试过)。
从 Windows 服务启动进程时出现问题
_________
| | * Process 1
| Service | -------> * Process ...
|_________| * Process n
服务使用的代码如下:
ProcessStartInfo startInfo = new ProcessStartInfo(executablePath, commandlineArgs);
startInfo.WorkingDirectory = instancePath;
startInfo.UserName = userB;
startInfo.Password = passwordSecureString;
startInfo.Domain = domain;
startInfo.UseShellExecute = false;
Process process = new Process
{
StartInfo = startInfo,
EnableRaisingEvents = true,
};
process.Start();
现在,我有两个帐户 - 为简单起见,假设为 A 和 B。服务在第一个帐户下 运行,并使用第二个帐户启动进程。
- 两个帐户都在本地管理员组中
- 两个账户都有权作为服务登录
- 已启用二次登录服务(以防万一,应该有关系)
- OS: Windows 服务器 2012 R2.
下面的table应该表示在哪个帐户星座中发生的事情。
_______________
| | A | B |
|===+=====+=====|
| A | OK | X |
|---+-----+-----|
| B | X | OK |
|___|_____|_____|
- 确定 - 进程按预期启动
- X - 服务没有错误,但进程立即终止。
...这让我假设用户更改导致了问题。
发生异常的详细信息:
在阅读了错误代码 142 之后,这是我目前所做的尝试:
- 不同的服务器
- Windows 更新
- Redistributable c++ 安装
- 咖啡,接着是烈酒,然后是咖啡
任何人都可以解决这个问题吗?
Stephen Martin 已经解释了这里发生的事情,所以如果您遇到原始问题中描述的问题,您可能会对以下博客 post 感兴趣:
http://asprosys.blogspot.de/2009/03/perils-and-pitfalls-of-launching.html
在这里,斯蒂芬解释说
Oops again, where is the process? Check the event log (or you may have received an Application Error pop-up). There should be an entry for Application Error that says that your process was the faulting application, either user32.dll or kernel32.dll was the faulting module and the exception was: 0xC0000142. There may be some minor variation in this but basically it is saying that your application could not initialize. The reason for this is that on initialization, before any application code is run, all processes are attached to a Window Station and all threads are attached to a Desktop but the user you are launching under does not have permission to access the Window Station and Desktop in which your process is being launched, ergo it can't initialize. The security descriptors for the Window Station and Desktop must be adjusted to give AllAccess permission to the user the process is being launched under. This is a devil to do directly in .Net, so you might find the security wrapper classes here useful
如果您不喜欢使用 Stephen 的库,您还可以查看提供的其他解决方案here(我还没有测试过)。