Reputation: 41
I'm trying to kill a process using a CMD command line from my C# application but when i start the application nothing happens... When i try to kill from command prompt i recieve the message: "Access denied". I've tried to run my app as Administrator and the process was killed. How can i manage not to always use "Run as Administrator"?
Code:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C taskkill /F /IM APP.EXE";
process.StartInfo = startInfo;
process.Start();
Upvotes: 3
Views: 12139
Reputation: 1
It's means that your application was ran under administrator, so you can kill it only under administrator too. Try too launch application under another user.
Hope this help.
Upvotes: 0
Reputation: 18127
Try this
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.UserName = "Administrator";
startInfo.Password = <password>;
startInfo.Arguments = "/C taskkill /F /IM APP.EXE";
process.StartInfo = startInfo;
process.Start();
Upvotes: 3
Reputation: 13620
You need to set this in the manifest
<requestedExecutionLevel level="requireAdministrator" uiAccess="true"/>
Upvotes: 0