Bravo dla mojego współpracownika (Bruce Eddy). Znalazł sposób możemy dokonać tego połączenia wiersza poleceń:
installutil.exe /user=uname /password=pw myservice.exe
Stało się nadrzędnymi 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;
}
}
}
Dla każdego, kto tego używa, upewnij się, że wszystkie argumenty poprzedzają ".exe" usługi w wierszu poleceń, w przeciwnym razie nie są przetwarzane/przekazywane. –
Dotyczy to nazwy użytkownika/hasła w pliku dziennika instalacji. Dopóki nie wyłączysz zapisywania logów, te informacje pozostaną, co jest dość niebezpieczne. Nie znalazłem jeszcze lepszego rozwiązania :( – flayn
Działa to nawet z ManagedInstallerClass ManagedInstallerClass.InstallHelper (nowy ciąg [] {"/ user = theUserName", "/ password = ******", Assembly. GetExecutingAssembly(). Lokalizacja}); –