C#检测产生的进程 [英] C# Detecting Spawned Processes

查看:130
本文介绍了C#检测产生的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一块一个启动安装程序,并等待它与其他的东西,然后再继续回到C#代码。



我有一定的麻烦该产卵其他过程与安装有实际完成之前的原始处理返回的安装程序。 有一些办法,我可以等待,直到所有的进程已经完成



要澄清这里是我遇到的麻烦的场景:<? / p>


  1. 启动Installer1

  2. Installer1派生/启动另一个安装程序(Installer2)

  3. 安装程序1返回

  4. 应用程序安装认为已完成,但Installer2仍在运行。这导致的问题与工作流程中的应用



下面是我目前使用的代码:

  //启动安装程序
工艺过程= windowsApplicationLauncher.LaunchApplication(_localFilePath);

//等待过程返回

{
如果(!process.HasExited)
{
}
}
,而(process.WaitForExit(1000)!);

如果(process.ExitCode == 0)
{
_fileService.MoveFile(_localFilePath,_postInstallFilePath);

_notification.SetComplete(假);

返回真;
}
返回FALSE;


解决方案

你有没有想过使用WMI来解决这个问题?



您可以使用WMI监听进程创建和删除事件。问 967668 有一个很好的例子。



当您收到一个进程创建事件,你可以发出一个WMI查询,以确定过程是一个孩子(或孩子等的孩子)你的根安装用类似下面的



SELECT * FROM Win32_Process的WHERE ParentProcessId =


I'm writing a piece of c# code that launches an installer and waits for it to return before continuing with other stuff.

I'm having trouble with certain installers that spawn other processes with the original process returning before the install has actual finished. Is there some way that I can wait until all the processes have finished?

To clarify here's the scenario I'm having trouble with:

  1. Launch Installer1
  2. Installer1 spawns/launches another installer (Installer2)
  3. Installer 1 returns
  4. Application thinks install has finished but Installer2 is still running. This causes issues with workflow in the app.

Here's the code I'm using at the moment:

// launch installer
Process process = windowsApplicationLauncher.LaunchApplication(_localFilePath);

// wait for process to return
do
{
    if (!process.HasExited)
    {
    }
}
while (!process.WaitForExit(1000));

if (process.ExitCode == 0)
{
    _fileService.MoveFile(_localFilePath, _postInstallFilePath);

    _notification.SetComplete(false);

    return true;
}
return false;

解决方案

Have you thought about using WMI to solve this problem?

You can use WMI to listen for process creation and deletion events. Question 967668 has a good example.

When you receive a process creation event, you could issue a WMI query to determine if the process is a child (or a child of a child etc) of your root installer with something like the following:

"SELECT * FROM Win32_Process WHERE ParentProcessId=".

这篇关于C#检测产生的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆