Korzystanie z InstallUtil i ciche ustawianie loginu/hasła usługi windows

Muszę użyć InstallUtil aby zainstalować usługę C # windows. Muszę ustawić poświadczenia logowania do usługi (nazwa użytkownika i hasło). Wszystko to musi być zrobione po cichu.

Jest sposób, aby zrobić coś takiego:

installutil.exe myservice.exe /customarg1=username /customarg2=password
Author: Craig Trader, 2008-09-26

5 answers

O wiele łatwiejszym sposobem niż powyższe posty i bez dodatkowego kodu w instalatorze jest użycie następującego kodu:

InstallUtil.exe / username=domain\username / password=password / unattended C:\My.exe

Upewnij się, że konto, z którego korzystasz, jest prawidłowe. Jeśli nie, otrzymasz wyjątek" nie wykonano mapowania między nazwami kont a identyfikatorami zabezpieczeń "

 64
Author: Jimbo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-29 11:29:01

Brawo dla mojego współpracownika (Bruce Eddy). Znalazł sposób na wywołanie tego wiersza poleceń:

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

Odbywa się to przez nadpisanie OnBeforeInstall w klasie instalatora:

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;
        }
    }
}
 51
Author: Dean Hill,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-09-26 15:36:15

InstallUtil.exe sets StartupType=Manual

W przypadku, gdy chcesz autostartować usługę, użyj:

sc config MyServiceName start= auto

(zauważ, że musi być spacja po'=')

 5
Author: Josua,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-13 19:22:51

Nie, installutil tego nie obsługuje.

Oczywiście, jeśli napisałeś instalator; z niestandardową akcją wtedy będziesz mógł go używać jako część MSI lub poprzez installutil.

 2
Author: blowdart,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-09-26 15:05:58

Możesz również wymusić uruchomienie usługi jako użytkownik za pomocą ServiceProcessInstaller:: Account = ServiceAccount.User ;

Podczas instalacji usługi pojawi się okienko z pytaniem "[domain\]user, password".

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;
     ....
 2
Author: william,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-23 14:31:37