Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Windows Service

Windows Service

Scheduled Pinned Locked Moved C#
windows-adminquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    ksanju1000
    wrote on last edited by
    #1

    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

    V 1 Reply Last reply
    0
    • K ksanju1000

      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

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      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/

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups