Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected override void OnBeforeInstall(IDictionary savedState)
- {
- base.OnBeforeInstall(savedState);
- bool isUserAccount = false;
- string name = GetContextoParametros("name");
- if (0 == name.Length) name = serviceInstaller.ServiceName;
- serviceInstaller.ServiceName = name;
- string display = GetContextoParametros("displayname");
- if (0 == display.Length) display = serviceInstaller.DisplayName;
- serviceInstaller.DisplayName = display;
- string acct = GetContextoParametros("account");
- switch (acct)
- {
- case "user":
- serviceProcessInstaller.Account =
- System.ServiceProcess.ServiceAccount.User;
- isUserAccount = true;
- break;
- case "localservice":
- serviceProcessInstaller.Account =
- System.ServiceProcess.ServiceAccount.LocalService;
- break;
- case "localsystem":
- serviceProcessInstaller.Account =
- System.ServiceProcess.ServiceAccount.LocalSystem;
- break;
- case "networkservice":
- serviceProcessInstaller.Account =
- System.ServiceProcess.ServiceAccount.NetworkService;
- break;
- }
- string username = GetContextoParametros("user");
- string password = GetContextoParametros("password");
- if (isUserAccount)
- {
- serviceProcessInstaller.Username = username;
- serviceProcessInstaller.Password = password;
- }
- }
- public override void Install(IDictionary stateServer)
- {
- RegistryKey system,
- //HKEY_LOCAL_MACHINEServicesCurrentControlSet
- currentControlSet,
- //...Services
- services,
- //...<Service Name>
- service,
- //...Parameters - this is where you can
- //put service-specific configuration
- config;
- base.Install(stateServer);
- system = Registry.LocalMachine.OpenSubKey("System");
- currentControlSet = system.OpenSubKey("CurrentControlSet");
- services = currentControlSet.OpenSubKey("Services");
- service =
- services.OpenSubKey(this.serviceInstaller.ServiceName, true);
- service.SetValue("Description",
- this.serviceInstaller.Description);
- Console.WriteLine("ImagePath: " + service.GetValue("ImagePath"));
- string imagePath = (string)service.GetValue("ImagePath");
- imagePath += " -s" + this.serviceInstaller.ServiceName;
- service.SetValue("ImagePath", imagePath);
- config = service.CreateSubKey("Parameters");
- config.Close();
- service.Close();
- services.Close();
- currentControlSet.Close();
- system.Close();
- }
- public string GetContextoParametros(string key)
- {
- string sValue = "";
- try
- {
- sValue = this.Context.Parameters[key].ToString();
- if (sValue.IndexOf(@"") >= 0)
- sValue = sValue.Substring(sValue.LastIndexOf(@""), sValue.Length - sValue.LastIndexOf(@""));
- }
- catch
- {
- sValue = "";
- }
- return sValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement