我需要使用InstallUtil安装C#windows服务。我需要设置服务登录凭据(用户名和密码)。所有这些都需要静静地完成。使用InstallUtil并静默设置Windows服务登录用户名/密码
是否有办法做这样的事情:
installutil.exe myservice.exe /customarg1=username /customarg2=password
我需要使用InstallUtil安装C#windows服务。我需要设置服务登录凭据(用户名和密码)。所有这些都需要静静地完成。使用InstallUtil并静默设置Windows服务登录用户名/密码
是否有办法做这样的事情:
installutil.exe myservice.exe /customarg1=username /customarg2=password
布拉沃给我的同事(布鲁斯艾迪)。他找到了一种方法,我们可以使此命令行电话:使用
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不支持。
当然,如果你写了一个安装程序;与custom action然后你将能够使用它作为MSI的一部分或通过installutil。
您还可以强制为您服务,为用户运行:
installutil.exe /user=uname /password=pw myservice.exe
它是由安装程序类中重写OnBeforeInstall完成ServiceProcessInstaller :: Account = ServiceAccount.User;
在服务安装过程中会弹出一个询问“[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;
....
-1该问题明确要求进行无提示安装 – 2014-03-12 11:21:31
比上面的帖子,并与您的安装没有额外的代码更简单的方法是使用以下命令:
installUtil.exe /用户名=域\用户名/密码=密码/无人值守C:\ My.exe
只要确保您使用的帐户有效。如果没有,你会收到一个“帐户名和安全的ID之间没有映射已完成”异常
InstallUtil.exe
设置StartupType =手动
如果你想自动启动该服务,使用:
sc config MyServiceName start= auto
(注意'='后必须有一个空格)
对于任何使用此操作的人,请确保所有参数都位于命令行上服务的“.exe”之前,否则它们不会被处理/传递。 – 2012-06-28 10:18:48
这将在安装日志文件中包含用户名/密码。除非您禁用日志文件的写入,否则这些信息将保留,这是非常危险的,我认为。我还没有找到更好的解决方案:( – flayn 2012-09-14 08:43:03
这甚至可以与ManagedInstallerClass ManagedInstallerClass.InstallHelper(新字符串[] {“/ user = theUserName”,“/ password = ******”,程序集。 GetExecutingAssembly()。Location}); – 2014-08-05 20:42:45