Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Killing a Prossess

Status
Not open for further replies.

hallmat

Programmer
Feb 14, 2008
1
GB
i know how to kill one but i cant seem to get the script to repeat it without throwing an error

maybe i can use a timer?

but everytime i try to add the timer it throws an exeption

Code:
for (; ; )
            {
                string processName = "DBT3";
                Process[] processes = Process.GetProcessesByName(processName);

                foreach (Process process in processes)
                {




                    process.Kill();

thats the snipit i need to repeat

error i get it Win32exeption was unhandled

Access is Denied
 
You have to make sure you have admin rights on this computer. Step through to make sure Process.GetProcessesByName() method isn't throwing the error. I remember an obscure error with this method.

If this is the case I can try to dig it up.

 
If the process is not found, the processes array variable will have a length of 0, which causes an error in your foreach loop.
Try checking the length, if > 0 then loop.
Code:
if (processes.Length > 0) {
     foreach (Process process in processes)
     {process.Kill()}
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top