如何将进程与我自己的应用程序进程VB.NET相关联 [英] How can i associate a process with my own application process VB.NET

查看:55
本文介绍了如何将进程与我自己的应用程序进程VB.NET相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



简而言之,我正在实施一个应用程序,使用Diagnostics.Process.Start在单击按钮时运行另一个应用程序()函数并监视该应用程序的进程。现在我的问题是这个,我想知道如何将应用程序的流程与我的.NET应用程序的流程启动usint Diagnostics.Process.Start()以及每当我的.NET应用程序关闭时的流程我运行的应用程序也将关闭。



我不想在Form1.FormClosing事件中处理这个问题。这样做的原因是可能会有一些有意义的用户可能会直接进入任务栏管理器并终止我的.NET应用程序进程并使应用程序的进程保持活动状态,从而删除我在.NET应用程序中编码的监视。



我需要帮助,我想知道如何将我的.NET应用程序和我使用Diagnostics.Process运行的第三方应用程序关联起来。启动()以便每当我的.NET应用程序关闭时,第三方应用程序也将关闭。



提前感谢!

解决方案

看来你的请求有一个解决方案。请看这里: http://stackoverflow.com/questions / 3342941 / kill-child-process-when-parent-process-is-killed#answer-4657392 [ ^ ]。该代码围绕作业对象工具构建[ ^ ]:

Quote:

作业对象允许将一组进程作为一个单元进行管理。作业对象是可命名的,安全的,可共享的对象,用于控制与其关联的进程的属性。对作业对象执行的操作会影响与作业对象关联的所有进程。示例包括强制执行限制,例如工作集大小和进程优先级,或终止与作业关联的所有进程。


之间没有关联进程。进程可以使用作业对象间接关联,请参阅解决方案2.同时,您可以自己处理您的子进程。 [结束编辑]



首先,请注意 Process.Start 返回外部进程的实例开始。您可以使用此实例来终止该过程: http://msdn.microsoft。 com / en-us / library / system.diagnostics.process.kill.aspx [ ^ ]。



相反,在外部过程中触发某事退出,您可以使用 Process.WaitForExit 方法:

http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ty0d8k56.aspx [ ^ ]。



由于此调用是阻止,在大多数情况下,需要一个单独的线程等待。



-SA

Hi everyone,

To cut the long story short, i am implementing an application that runs another application during a click of a button using Diagnostics.Process.Start() function and also monitor the process of that application. Now my problem is this, i want to know how i can associate the process of the application i started usint Diagnostics.Process.Start() with the process of my .NET application so what whenever my .NET application closes, the process of the application i ran will also close.

I don't want to handle this in the Form1.FormClosing Event. The reason for this is because there might be some malcious users that might go straight into the taskbar manager and terminate the process of my .NET application and leaving the process of the application i ran active thereby removing the monitoring i coded inside my .NET application.

Pls i need help on this, i want to know how i can associate the process of my .NET application and the third party application i ran using Diagnostics.Process.Start() so that whenever my .NET application shuts down, the third party application will also shut down.

Thanks in advance!

解决方案

It look that there is a solution to your request. Look here: http://stackoverflow.com/questions/3342941/kill-child-process-when-parent-process-is-killed#answer-4657392[^]. The code is built around the Job Object tool[^]:

Quote:

A job object allows groups of processes to be managed as a unit. Job objects are namable, securable, sharable objects that control attributes of the processes associated with them. Operations performed on a job object affect all processes associated with the job object. Examples include enforcing limits such as working set size and process priority or terminating all processes associated with a job.


[EDIT]There is no such thing as association between processes. Processes can be indirectly associated using the job objects, please see Solution 2. At the same time, you can take care about your child processes by yourself. [END EDIT]

First of all, note that Process.Start returns you the instance of the external process started. You can use this instance to kill the process: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill.aspx[^].

To do the opposite, to trigger something when the external process is exited, you can use Process.WaitForExit methods:
http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx[^],
http://msdn.microsoft.com/en-us/library/ty0d8k56.aspx[^].

As this call is blocking, in most cases, a separate thread is required to wait.

—SA


这篇关于如何将进程与我自己的应用程序进程VB.NET相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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