• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

problem in killing process

hi,
I use this code to kill the process

            Process[] clsProcess = Process.GetProcessesByName(processName);
            if (clsProcess.Length > 0)
            {
                foreach (Process process in clsProcess)
                {
                    System.Diagnostics.Process.EnterDebugMode();
                    process.Kill();
                }
                isPgProcessRunning = CheckProcessExistance(processName);
                DiagnoseProcess(isPgProcessRunning);
            }

this function to check the status of process (running or not):
        private bool CheckProcessExistance(string processName)
        {
            try
            {
                Process[] clsProcess = Process.GetProcessesByName(processName);
                if (clsProcess.Length > 0)
                    return true;
                else
                    return false;
            }
            catch
            {
                return false;
            }
        }

so its giving in this line  isPgProcessRunning = CheckProcessExistance(processName); that the process is running, even it has been killed !!

any idea how to fix that ??
0
Ameerh24
Asked:
Ameerh24
  • 4
  • 3
  • 2
  • +1
1 Solution
 
DeathraceCommented:
Hey,
Comment the below line..
System.Diagnostics.Process.EnterDebugMode(); , run the code and check ...it will work.
0
 
Ameerh24Author Commented:
but there would a problem ....... this process is a system process ( developed to be as a system process ) and if I comment this line System.Diagnostics.Process.EnterDebugMode();
it will give me an error "Access is denied"

so what to do ?!!
0
 
Bob LearnedCommented:
What process are you trying to kill?  Is it a "killable" process?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Ameerh24Author Commented:
yes of course (its "pg.exe" ) , but the problem is this process is typed as system process
0
 
Bob LearnedCommented:
Are you trying to attack a virus/trojan horse with your own program?
0
 
Ameerh24Author Commented:
no at all !!!!
there is no viruses or trojans !!
we have developed this program but for importance, another engineer who developed this program make it as a system process .... this is it

and I just need to turn on, off the process regrading some other conditions
0
 
DeathraceCommented:
If the call to the Kill method is made while the process is currently terminating, a Win32Exception is thrown for Access Denied.

check the note
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill.aspx
0
 
CodeCruiserCommented:
I think making the process a System Process is causing the Access Denied exception.
0
 
Ameerh24Author Commented:
I did not understand, what to do now ?!!

how will I kill the system process and check it is killed ?
0
 
DeathraceCommented:
Try this...
Run your VS in admin mode if you are using windows vista and run your code and see whether it is capable of killing a process.

To run VS in admin mode:
Right the VS Lnks and use "Run as administrator" ...check this and let us know..
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now