1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60:
| #region Klasse IntegratedServiceInstaller (Dienst) class IntegratedServiceInstaller { public void Install(String ServiceName, String DisplayName, String Description, System.ServiceProcess.ServiceAccount Account, System.ServiceProcess.ServiceStartMode StartMode, string _path, string _logpath) { System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller(); ProcessInstaller.Account = Account;
System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();
System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext();
String path = String.Format("/assemblypath={0}", _path); String[] cmdline = { path }; Context = new System.Configuration.Install.InstallContext(_logpath, cmdline);
SINST.Context = Context; SINST.DisplayName = String.Format(DisplayName); SINST.Description = String.Format(Description); SINST.ServiceName = String.Format(ServiceName); SINST.StartType = StartMode; SINST.Parent = ProcessInstaller; string _exeName = Application.StartupPath + @"\ssSERV.exe";
System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary(); SINST.Install(state);
using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + ServiceName, true)) { try { Object sValue = oKey.GetValue("ImagePath"); oKey.SetValue("ImagePath", sValue); } catch (Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); } }
} public void Uninstall(String ServiceName, string _logpath) { System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();
System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext(_logpath, null); SINST.Context = Context; SINST.ServiceName = ServiceName; SINST.Uninstall(null); } }
#endregion |