Usando InstallUtil y configurando silenciosamente un nombre de usuario/contraseña de inicio de sesión del servicio de Windows
Necesito usar InstallUtil para instalar un servicio de windows C#. Necesito establecer las credenciales de inicio de sesión del servicio (nombre de usuario y contraseña). Todo esto debe hacerse en silencio.
Hay una manera de hacer algo como esto:
installutil.exe myservice.exe /customarg1=username /customarg2=password
5 answers
Una forma mucho más fácil que las publicaciones anteriores y sin código adicional en su instalador es usar lo siguiente:
InstallUtil.exe / username=domain \ username / password = password / unattended C:\My.exe
Solo asegúrese de que la cuenta que utiliza sea válida. Si no, recibirá una excepción de" No se realizó ninguna asignación entre los nombres de cuenta y los ID de seguridad "
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-29 11:29:01
Bravo a mi compañero de trabajo (Bruce Eddy). Encontró una manera de hacer esta llamada de línea de comandos:
installutil.exe /user=uname /password=pw myservice.exe
Se hace sobreescribiendo OnBeforeInstall en la clase del instalador:
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;
}
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-09-26 15:36:15
InstallUtil.exe
establece StartupType = Manual
En caso de que desee iniciar automáticamente el servicio, utilice:
sc config MyServiceName start= auto
(tenga en cuenta que tiene que haber un espacio después de'=')
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-13 19:22:51
No, installutil no soporta eso.
Por supuesto si escribiste un instalador; con una acción personalizada entonces podrías usar eso como parte de un MSI o a través de installutil.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-09-26 15:05:58
También puede forzar que su servicio se ejecute como usuario usando ServiceProcessInstaller::Account = ServiceAccount.Usuario;
Una ventana emergente preguntando "[domain\] user, password" aparecerá durante la instalación del servicio.
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;
....
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-10-23 14:31:37