1

How can I kill the parent process without administrator rights? Process A creates process B, and in process B I need to kill process A.

alex
  • 3,710
  • 32
  • 44
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286
  • possible duplicate of [C++ TerminateProcess function](http://stackoverflow.com/questions/2443738/c-terminateprocess-function) – Aamir Sep 30 '11 at 12:10
  • how about using IPC and an exit token instead (this is graceful exit instead of process kill)? or are you unable to edit the source for proces A? – mtijn Sep 30 '11 at 12:10
  • 1
    @lsk Please answer the questions you are asked - Don'tjust say thanks –  Sep 30 '11 at 12:15
  • "or are you unable to edit the source for proces A?" what do you mean by "source" of process? Process A and process B run me (they runs by me) – WelcomeTo Sep 30 '11 at 12:17
  • Are you kidding?? Source as in sourcecode. – Eight-Bit Guru Sep 30 '11 at 12:19
  • I have source code for both processes – WelcomeTo Sep 30 '11 at 12:21
  • 3
    let me put it this way: can you edit the source code of the executable of A? if not then you should accept the answer that suggests using the taskkill tool, if so then you have other options to end process A gracefully. this info should have been in your question so we can give you more meaningful answers. – mtijn Sep 30 '11 at 12:22
  • yes, mtijn, i have source code for both applications (for processes). Important to kill it without admin rights – WelcomeTo Sep 30 '11 at 12:26
  • yes of course, your answer and some others is good. I have added rank for you. – WelcomeTo Sep 30 '11 at 12:57

4 Answers4

2

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();
2

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

Community
  • 1
  • 1
Peter Kelly
  • 14,253
  • 6
  • 54
  • 63
2

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.

mtijn
  • 3,610
  • 2
  • 33
  • 55
0

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.

Tadeusz
  • 6,453
  • 9
  • 40
  • 58
  • 1
    ProcessB does not have admin privileges to kill other processes. – Peter Kelly Sep 30 '11 at 13:01
  • Then there are two ways: 1) To run another process from user with administrator's rights 2)"Ask" parent process to terminate itself (if It is your application) – Tadeusz Sep 30 '11 at 13:06
  • @Praetor12 but actually he mentioned that he doesn't have administative privilages, so that `Process.Kill` is meaningless here –  Sep 30 '11 at 13:13
  • @Mr.DDD Taskkill, running form non-privilieged user, will be with the same user privilieges... – Tadeusz Sep 30 '11 at 13:17