How can I kill the parent process without administrator rights? Process开发者_如何学C A creates process B, and in process B I need to kill process A.
You want to ProcessB to signal to ProcessA that it wants to it to stop running. ProcessA can then clean up any resources and exit gracefully (as suggested in the comments to your answer). 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.
A simple option is a system-wide EventWaitHandle - good example here Signalling to a parent process that a child process is fully initialised
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. you could also use taskkill but not ending A gracefully could result in corrupting resources A uses.
Check this:
Taskkill
Ends one or more tasks or processes. Processes can be killed by process ID or image name. Syntax
taskkill [/s Computer] [/u Domain\User [/p Password]]] [/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.
You can start a process in C# like:
using System.Diagnostics;
string args = ""; // write here a space separated parameter list for TASKKILL
Process prc = new Process(new ProcessStartInfo("Taskkill", args));
prc.Start();
All is very simple if you know parentProcessName, then solution is:
System.Diagnostics.Process.GetProcessesByName ("ParentProcessName")[0].Kill();
If not, then it will be a bit harder.
精彩评论