문제

C# Windows 서비스를 설치하려면 InstallUtil을 사용해야합니다. 서비스 로그 자격 증명 (사용자 이름 및 비밀번호)을 설정해야합니다. 이 모든 것은 조용히해야합니다.

다음과 같이 할 수있는 방법이 있습니까?

installutil.exe myservice.exe /customarg1=username /customarg2=password
도움이 되었습니까?

해결책 2

내 동료 (Bruce Eddy)에게 브라보. 그는 우리 가이 명령 줄을 할 수있는 방법을 찾았습니다.

installutil.exe /user=uname /password=pw myservice.exe

설치 프로그램 클래스에서 onbeforeinstall을 재정의하여 수행됩니다.

namespace Test
{
    [RunInstaller(true)]
    public class TestInstaller : Installer
    {
        private ServiceInstaller serviceInstaller;
        private ServiceProcessInstaller serviceProcessInstaller;

        public OregonDatabaseWinServiceInstaller()
        {
            serviceInstaller = new ServiceInstaller();
            serviceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
            serviceInstaller.ServiceName = "Test";
            serviceInstaller.DisplayName = "Test Service";
            serviceInstaller.Description = "Test";
            serviceInstaller.StartType = ServiceStartMode.Automatic;
            Installers.Add(serviceInstaller);

            serviceProcessInstaller = new ServiceProcessInstaller();
            serviceProcessInstaller.Account = ServiceAccount.User; 
            Installers.Add(serviceProcessInstaller);
        }

        public string GetContextParameter(string key)
        {
            string sValue = "";
            try
            {
                sValue = this.Context.Parameters[key].ToString();
            }
            catch
            {
                sValue = "";
            }
            return sValue;
        }


        // Override the 'OnBeforeInstall' method.
        protected override void OnBeforeInstall(IDictionary savedState)
        {
            base.OnBeforeInstall(savedState);

            string username = GetContextParameter("user").Trim();
            string password = GetContextParameter("password").Trim();

            if (username != "")
                serviceProcessInstaller.Username = username;
            if (password != "")
                serviceProcessInstaller.Password = password;
        }
    }
}

다른 팁

위의 게시물보다 훨씬 쉬운 방법과 설치 프로그램에 추가 코드가없는 것은 다음을 사용하는 것입니다.

installutil.exe /username = domain username /password = password /무인 c : my.exe

사용하는 계정이 유효한지 확인하십시오. 그렇지 않으면 "계정 이름과 보안 ID 사이에 매핑이 없음"예외를 받게됩니다.

InstallUtil.exe startuptype = 매뉴얼을 설정합니다

서비스를 자동화하려는 경우 다음을 사용하십시오.

sc config MyServiceName start= auto

( '='이후에 공간이 있어야합니다)

아니요, installUtil은이를 지원하지 않습니다.

물론 설치 프로그램을 작성한 경우; a 사용자 정의 액션 그런 다음 MSI의 일부 또는 InstallUtil을 통해 사용할 수 있습니다.

또한 서비스를 사용하여 사용자로서 실행하도록 강요 할 수도 있습니다.ServiceProcessInstaller :: account = serviceaccount.user;

서비스 설치 중에 [Domain ] 사용자, 비밀번호"를 요청하는 팝업이 나타납니다.

public class MyServiceInstaller : Installer
{
    /// Public Constructor for WindowsServiceInstaller
    public MyServiceInstaller()
    {
        ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
        ServiceInstaller serviceInstaller = new ServiceInstaller();

        //# Service Account Information
        serviceProcessInstaller.Account = ServiceAccount.User; // and not LocalSystem;
     ....
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top