简体   繁体   English

在没有管理员权限的情况下终止父进程

[英]Kill parent process without administrator rights

How can I kill the parent process without administrator rights? 没有管理员权限,如何杀死父进程? Process A creates process B, and in process BI need to kill process A. 进程A创建了进程B,并且在进程BI中需要终止进程A。

Check this : 检查一下

Taskkill 任务杀手

Ends one or more tasks or processes. 结束一个或多个任务或过程。 Processes can be killed by process ID or image name. 可以通过进程ID或映像名称杀死进程。 Syntax 句法

taskkill [/s Computer] [/u Domain\\User [/p Password]]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t] taskkill [/ s计算机] [/ u域\\用户[/ p密码]]] [/ fi FilterName] [/ pid ProcessID] | [/ im ImageName] [/ f] [/ t]

/t : Specifies to terminate all child processes along with the parent process, commonly known as a tree kill. / t:指定终止所有子进程以及父进程,通常称为树杀。

You can start a process in C# like: 您可以像这样在C#中启动一个过程:

using System.Diagnostics;

string args = ""; // write here a space separated parameter list for TASKKILL
Process prc = new Process(new ProcessStartInfo("Taskkill", args));
prc.Start();

You want to ProcessB to signal to ProcessA that it wants to it to stop running. 您要让ProcessB向ProcessA发出信号,告知它要停止运行。 ProcessA can then clean up any resources and exit gracefully (as suggested in the comments to your answer). 然后,ProcessA可以清理所有资源并正常退出(如答案注释中所建议)。 So how does a Process signal something to another Process? 那么一个流程如何向另一个流程发出信号呢? That is called Inter-Process Communication (IPC) and there are loads of ways to do on the same machine or across machines including message buses, web-service, named pipes. 这就是所谓的进程间通信(IPC),在同一台机器上或跨机器的工作方式很多,包括消息总线,Web服务,命名管道。

A simple option is a system-wide EventWaitHandle - good example here Signalling to a parent process that a child process is fully initialised 一个简单的选项是系统范围内的EventWaitHandle-很好的示例, 向父进程发信号通知子进程已完全初始化

so you have the source code for both processes. 因此您拥有这两个过程的源代码。 in this case you can use a named system event like a semaphore to gracefully end process A. for example, construct a named semaphore in process A, pass the name to process B as one of the command line parameters when starting process B. Open the existing named semaphore from process B and signal it to let process A know it can end. 在这种情况下可以使用一个命名系统事件像信号量优雅地结束处理A.例如, 构造一个命名信号量在处理A中,通过起动过程B.何时处理B作为命令行参数之一的名称打开来自进程B的现有已命名信号量 ,并发出信号通知进程A知道它可以结束。 you could also use taskkill but not ending A gracefully could result in corrupting resources A uses. 您也可以使用taskkill,但不能以A结尾就不会优雅地导致A使用的资源损坏。

All is very simple if you know parentProcessName, then solution is: 如果您知道parentProcessName,那么一切都非常简单,那么解决方案是:

System.Diagnostics.Process.GetProcessesByName ("ParentProcessName")[0].Kill();

If not, then it will be a bit harder. 如果没有,那么会有点困难。

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

相关问题 在没有管理员权限的情况下运行WinForms应用程序? - Run WinForms application without administrator rights? 没有管理员权限的VSTO插件和运行时 - VSTO addin and runtime without administrator rights ABCpdf AddImageHtml文本拉伸没有管理员权限 - ABCpdf AddImageHtml text stretches without administrator rights 如何在没有我的WPF主机的情况下启动具有管理员权限的进程,并且还运行管理员权限以实现文件拖放? - How do I start a process with administrator privileges without my WPF host also runs with admin rights in order to implement file drag & drop? 以管理员身份启动流程,不使用UseShellExecute? - Start Process as Administrator, without UseShellExecute? Visual Studio 安装项目:在没有管理员权限的情况下运行 msi 安装程序 - Visual Studio Setup Project: Run the msi installer without administrator rights 如何在Windows 7操作系统中获得没有管理员权限的注册表项 - how to get registry key without having administrator rights in windows 7 OS 是否可以安装将程序集放入GAC而无需管理员权限的程序? - Is it possible to install a program that puts assemblies into the GAC without administrator rights? 当父进程被杀死时杀死子进程 - Kill child process when parent process is killed 在没有管理员权限的情况下检测运行过程的结束 - Detect end of running process without Admin rights
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM