Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 124549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:01:04+00:00 2026-05-11T05:01:04+00:00

I want to kill a process programmatically in vista/windows 7 (I’m not sure if

  • 0

I want to kill a process programmatically in vista/windows 7 (I’m not sure if there’s significant problems in the implementation of the UAC between the two to make a difference).

Right now, my code looks like:

  if(killProcess){       System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName('MyProcessName');        // Before starting the new process make sure no other MyProcessName is running.         foreach (System.Diagnostics.Process p in process)         {             p.Kill();         }          myProcess = System.Diagnostics.Process.Start(psi);    } 

I have to do this because I need to make sure that if the user crashes the program or exits abruptly, this secondary process is restarted when the application is restarted, or if the user wants to change the parameters for this secondary process.

The code works fine in XP, but fails in Windows 7 (and I assume in Vista) with an ‘access is denied’ message. From what the Almighty Google has told me, I need to run my killing program as administrator to get around this problem, but that’s just weak sauce. The other potential answer is to use LinkDemand, but I don’t understand the msdn page for LinkDemand as it pertains to processes.

I could move the code into a thread, but that has a whole host of other difficulties inherent to it that I really don’t want to discover.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:01:05+00:00Added an answer on May 11, 2026 at 5:01 am

    You are correct in that it’s because you don’t have administrative priveleges. You can solve this by installing a service under the local system user and running a custom command against it as needed.

    In your windows form app:

    private enum SimpleServiceCustomCommands { KillProcess = 128 };  ServiceControllerPermission scp = new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, Environment.MachineName, 'SERVICE_NAME'); scp.Assert(); System.ServiceProcess.ServiceController serviceCon = new System.ServiceProcess.ServiceController('SERVICE_NAME', Environment.MachineName); serviceCon.ExecuteCommand((int)SimpleServiceCustomCommands.KillProcess);  myProcess = System.Diagnostics.Process.Start(psi); 

    In your service:

    private enum SimpleServiceCustomCommands { KillProcess = 128 };  protected override void OnCustomCommand(int command) {     switch (command)     {         case (int)SimpleServiceCustomCommands.KillProcess:             if(killProcess)             {                 System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName('MyProcessName');                 // Before starting the new process make sure no other MyProcessName is running.                 foreach (System.Diagnostics.Process p in process)                 {                     p.Kill();                 }             }             break;         default:             break;     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to kill a whole process tree. What is the best way to
i want to get the running process in .net compact framework windows mobile.. i
I want to kill a process running on the machine using taskkill if they're
In C++ is there a way to unconditionally kill a process? No matter what
I run an external program with C++: _wsystem(exec); I want to kill the process
I want to act with a service (kill the procces) whenever a process (executable
I've a small C# installer application and I want to kill a process. Are
I want to kill an executable of a game named KnightOnline and deny user
I'm having trouble with a process forking exercise. I want to fork a child
I want to delete file on windows OS using java, how ever some time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.