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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 110k
  • Answers 110k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If it's tabular data, you can use a table. If… May 11, 2026 at 9:39 pm
  • Editorial Team
    Editorial Team added an answer Your destroy_tree() is called twice, you call it once and… May 11, 2026 at 9:39 pm
  • Editorial Team
    Editorial Team added an answer No, it is not considered good practice. On the contrary,… May 11, 2026 at 9:39 pm

Related Questions

I want to kill a process programmatically in vista/windows 7 (I'm not sure if
I want to kill a whole process tree. What is the best way to
I need a Java way to find a running Win process from which I
We have a C++ task that will fork a new process. That process in
After opening a pipe to a process with popen , is there a way

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.