locked
Widows Service RRS feed

  • Question

  • I have created Windows Service named RockwellEDK in .net 2008 but when I try to install it through command line (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe c:\RockwellEDK.exe) it shows an error The file name,directory name, or volume label syntax is incorrect.If I do install like this C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>InstallUtil.exe c:\RockwellEDK.exe then sends an error System.IO.FileNotFoundException:Could not load file and assembly 'file:///c:\RockwellEDK.exe' or one of itsdependencies.the system can not find the file specified... l am creating Windows Service first time,Would you help me.
    Friday, May 21, 2010 6:36 AM

Answers

  • I have created Windows Service named RockwellEDK in .net 2008 but when I try to install it through command line (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe c:\RockwellEDK.exe ) it shows an error The file name,directory name, or volume label syntax is incorrect .If I do install like this C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>InstallUtil.exe c:\RockwellEDK.exe then sends an error System.IO.FileNotFoundException:Could not load file and assembly 'file:///c:\RockwellEDK.exe' or one of itsdependencies.the system can not find the file specified.. . l am creating Windows Service first time,Would you help me.

    Please make sure your file path

     
     // You can also try this way to install your service
     // The form has a button and textbox
     // btnInstall and txtFilePath
     
     
     
         public bool Install(IDictionary stateSaver, string filepath, string serviceName)
        {
          try
          {
            service = new System.ServiceProcess.ServiceController(serviceName);
            if (!ServiceIsExisted(serviceName))
            {
              //Install Service
              AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
              myAssemblyInstaller.UseNewContext = true;
              myAssemblyInstaller.Path = filepath;
              myAssemblyInstaller.Install(stateSaver);
              myAssemblyInstaller.Commit(stateSaver);
              myAssemblyInstaller.Dispose();
              //--Start Service
              service.Start();
              return true;
              
            }
            else if (service.Status != System.ServiceProcess.ServiceControllerStatus.Running && service.Status != System.ServiceProcess.ServiceControllerStatus.StartPending)
            {
              service.Start();
              return true;
    
            }
            else
            {
              return false;
            }
            
            
          }
          catch (Exception ex)
          {
            throw new Exception("installServiceError\n" + ex.Message);
          }
        }
     
      
        private void btnInstall_Click(object sender, EventArgs e)
        {
          if (File.Exists(txtFilePath.Text.Trim()))
          {
            IDictionary backupService = new Hashtable();
            result = this.Install(backupService, txtFilePath.Text.Trim(),"BackupService"); // "BackupService" is Service Name
            if (result)
            {
               MessageBox.Show("Service Install Finish");
            }
           }
          
        }
    


    If (My Answer) Please mark the replies as answer. Thanks; Else Thank you all the same; My Code Blog:http://nauhil.wordpress.com/
    • Proposed as answer by Huan Li Tuesday, May 25, 2010 5:56 AM
    • Marked as answer by Harry Zhu Friday, May 28, 2010 5:29 AM
    Friday, May 21, 2010 7:12 AM

All replies

  • I have created Windows Service named RockwellEDK in .net 2008 but when I try to install it through command line (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe c:\RockwellEDK.exe ) it shows an error The file name,directory name, or volume label syntax is incorrect .If I do install like this C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>InstallUtil.exe c:\RockwellEDK.exe then sends an error System.IO.FileNotFoundException:Could not load file and assembly 'file:///c:\RockwellEDK.exe' or one of itsdependencies.the system can not find the file specified.. . l am creating Windows Service first time,Would you help me.

    Please make sure your file path

     
     // You can also try this way to install your service
     // The form has a button and textbox
     // btnInstall and txtFilePath
     
     
     
         public bool Install(IDictionary stateSaver, string filepath, string serviceName)
        {
          try
          {
            service = new System.ServiceProcess.ServiceController(serviceName);
            if (!ServiceIsExisted(serviceName))
            {
              //Install Service
              AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
              myAssemblyInstaller.UseNewContext = true;
              myAssemblyInstaller.Path = filepath;
              myAssemblyInstaller.Install(stateSaver);
              myAssemblyInstaller.Commit(stateSaver);
              myAssemblyInstaller.Dispose();
              //--Start Service
              service.Start();
              return true;
              
            }
            else if (service.Status != System.ServiceProcess.ServiceControllerStatus.Running && service.Status != System.ServiceProcess.ServiceControllerStatus.StartPending)
            {
              service.Start();
              return true;
    
            }
            else
            {
              return false;
            }
            
            
          }
          catch (Exception ex)
          {
            throw new Exception("installServiceError\n" + ex.Message);
          }
        }
     
      
        private void btnInstall_Click(object sender, EventArgs e)
        {
          if (File.Exists(txtFilePath.Text.Trim()))
          {
            IDictionary backupService = new Hashtable();
            result = this.Install(backupService, txtFilePath.Text.Trim(),"BackupService"); // "BackupService" is Service Name
            if (result)
            {
               MessageBox.Show("Service Install Finish");
            }
           }
          
        }
    


    If (My Answer) Please mark the replies as answer. Thanks; Else Thank you all the same; My Code Blog:http://nauhil.wordpress.com/
    • Proposed as answer by Huan Li Tuesday, May 25, 2010 5:56 AM
    • Marked as answer by Harry Zhu Friday, May 28, 2010 5:29 AM
    Friday, May 21, 2010 7:12 AM
  • Hello,

                       
             Try out using     C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe "c:\RockwellEDK.exe".  

               Place inverted comma ("") between your service path.

             You can install windows service through setup project also.

     

    Thanks,

    Paras Sanghani

    Friday, May 21, 2010 8:14 AM