Ji Ra
Ji Ra

Reputation: 3297

Install Windows Service With Startup Parameter

i am trying to install windows service with start up parameters with batch file.

i have service name which is passed in installer to get instance name. also i want to set service start up parameter. with passing arg to installer i do not have problem. i am getting error on startup parameter setting.

code snippet:

  set serviceName=FSER

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe  /servicename="%serviceName%"  "%UserProfile%\AppData\Local\SERVER\%serviceName%\tser.exe "%serviceName%" " /logfile=install.log

Upvotes: 0

Views: 7842

Answers (2)

Ji Ra
Ji Ra

Reputation: 3297

i Solved problem by adding parameter in Service installer "Assemblypath":

   protected override void OnBeforeInstall(IDictionary savedState)
        {                
                string parameter = "YOUR COMMAND LINE PARAMETER VALUE GOES HERE";
                var assemblyPath = Context.Parameters["assemblypath"];
                assemblyPath += @""" "" " + parameter + "";
                Context.Parameters["assemblypath"] = assemblyPath;
                base.OnBeforeInstall(savedState);
        }

Upvotes: 2

MC ND
MC ND

Reputation: 70923

Problematic use of quotes ? Try to escape inner quotes with backslashes, as

"\"myExeFile.exe\" \"myParameter\""

Don't really know about InstallUtil, but it that fails, and InstallUtil is needed, install service with InstallUtil but without parameters and then use sc.exe to reconfigure the service, including parameters in in binPath

Upvotes: 0

Related Questions