Windows Service
-
hi, I am making Windows Service(User defined) I have written code inside OnStart within Windows Service Inside the onstart i want that suppose a.exe is already running I want to close that a.exe and start a.exe from windows Service When i run the windows Service two exe runs cocuurently. On Start i have written Process.Start(@"c:\a.exe"); I want to identify in beginning of any process of a.exe if exist how can i check in windows service OnStart() protected override void OnStart(string[] args) { // TODO: Add code here to start your service. Process[] aProcesses1; if (aProcesses1.Length > 0) { if(rd1==true) { // The last excel process is the orphaned process which is killed aProcesses1[aProcesses1.Length-1].Kill(); rd1=false; } } int intExcelPID; aProcesses1=Process.GetProcessesByName("a"); 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); } Thanks sanjeev
-
hi, I am making Windows Service(User defined) I have written code inside OnStart within Windows Service Inside the onstart i want that suppose a.exe is already running I want to close that a.exe and start a.exe from windows Service When i run the windows Service two exe runs cocuurently. On Start i have written Process.Start(@"c:\a.exe"); I want to identify in beginning of any process of a.exe if exist how can i check in windows service OnStart() protected override void OnStart(string[] args) { // TODO: Add code here to start your service. Process[] aProcesses1; if (aProcesses1.Length > 0) { if(rd1==true) { // The last excel process is the orphaned process which is killed aProcesses1[aProcesses1.Length-1].Kill(); rd1=false; } } int intExcelPID; aProcesses1=Process.GetProcessesByName("a"); 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); } Thanks sanjeev
Sanjeev: It seems you have a duplicated post. The post carries the solution. You can check via GetProcessesByName. Deepak Kumar Vasudevan Personal Web: http://vdeepakkumar.netfirms.com/ I Blog At: http://deepak.blogdrive.com/