Wow. Where to begin... First, you've put this in the the OnStart procedure of your service. This means that it will only run ONCE per start of the service or on startup of Windows. OnStart is meant for you to start your service code, possibly on another thread. The way you have it setup, your code will execute once, then stop. The error comes up because you have a problem with your code in the OnStart() method. You've got ALOT of problems with this code.
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
Process\[\] aProcesses1;
if (aProcesses1.Length > 0)
{
if(rd1==true)
{
**// The below statement is NOT true! The last Excel process in NOT
// guaranteed to be the orphaned process! Whatever you mean by this...**
// The last excel process is the orphaned process which is killed
**// Your code here is killing off the second to last process in the
// list, WHATEVER this process is, even a System process! <- BAD!
// You're not checking to see if it is Excel!
// On top of that, you're not even retrieving the list of processes.
// All your doing is creating a process object that doesn't represent
// any process and trying to call Kill on it. THIS WILL FAIL!
aProcesses1\[aProcesses1.Length-1\].Kill();
rd1=false;
}
}
int intExcelPID;
aProcesses1=Process.GetProcessesByName("man");
string strProc="These are the processes running \\n";
for (int i = 0; i <= aProcesses1.GetUpperBound(0); i++)
{
intExcelPID = aProcesses1\[i\].Id;
strProc+=intExcelPID.ToString()+ " ";
}
//Retrive from registry the value of Path
RegistryKey hklm=Registry.LocalMachine;
hklm=hklm.OpenSubKey("SOFTWARE\\\\man");
Object obp=hklm.GetValue("Path");
string file=obp.ToString() + "\\\\man.exe";
Process.Start(@file);
}**
But first, I take it your trying to find Excel processes that are left open by an application? Why? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome