?
Solved

problem in killing process

Posted on 2010-01-10
10
Medium Priority
?
423 Views
Last Modified: 2013-12-17
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
Comment
Question by:Ameerh24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 9

Expert Comment

by:Deathrace
ID: 26277471
Hey,
Comment the below line..
System.Diagnostics.Process.EnterDebugMode(); , run the code and check ...it will work.
0
 

Author Comment

by:Ameerh24
ID: 26278337
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26278579
What process are you trying to kill?  Is it a "killable" process?
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:Ameerh24
ID: 26278871
yes of course (its "pg.exe" ) , but the problem is this process is typed as system process
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26278889
Are you trying to attack a virus/trojan horse with your own program?
0
 

Author Comment

by:Ameerh24
ID: 26280314
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
 
LVL 9

Expert Comment

by:Deathrace
ID: 26281260
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26305037
I think making the process a System Process is causing the Access Denied exception.
0
 

Author Comment

by:Ameerh24
ID: 26324377
I did not understand, what to do now ?!!

how will I kill the system process and check it is killed ?
0
 
LVL 9

Accepted Solution

by:
Deathrace earned 2000 total points
ID: 26334102
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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question