Problems installing a service in Windows Server

2
  • Developed an application in Windows Service, in Visual Studio;
  • IcannotinstalltheserviceonWindowsServer;
  • asked by anonymous 19.09.2014 / 19:04

    2 answers

    2

    Are you running Prompt as an administrator? If it is windows 8 I suggest you try doing the same operation on a window 7.

    But I already had some problems with installutil.exe ... so I do the following:

    Add the reference System.Configuration.Install to your service in visual studio. In Main.cs or Program.cs (depends on your application) put the following code:

    static void Main(string[] args)
    {
        if (Environment.UserInteractive)
        {
            string parameter = string.Concat(args);
            switch (parameter)
            {
                case "--install":
                ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
                break;
                case "--uninstall":
                ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
                break;
            }
        }
        else
        {
        //aqui é seu codigo para rodar o serviço normalmente.
            ServiceBase[] servicesToRun = new ServiceBase[] 
                              { 
                                  new ValidatorService() 
                              };
            ServiceBase.Run(servicesToRun);
        }
    }
    

    Now you just call in the cmd generated program: Servico.exe with the --install argument to install the service ... to uninstall use the --uninstall. And now you can throw out installutil.exe

        
    19.09.2014 / 20:36
    2

    By deduction, it seems that the G:\ unit corresponds to a network mapping . In this case, the installation will actually fail.

    Try to move all dependencies to a local drive ( C: ) and install the service into that directory.

    If G:\ is a mapping to a drive of the local machine itself, use the original path to which the mapping points to register the service executable. Example:

    installutil.exe c:\meu_mapeamento\iERP\(...)\iServicos.exe

        
    19.09.2014 / 21:02