Install Windows Service With Startup Parameter

北城余情 提交于 2019-12-11 23:28:52

问题


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

回答1:


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);
        }



回答2:


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



来源:https://stackoverflow.com/questions/19378377/install-windows-service-with-startup-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!