public static void UninstallService() { try { IntegratedServiceInstaller.Uninstall(PSService.PSServiceName); } catch { } }
public static void InstallService(ServiceAccount account, ServiceStartMode startMode, string username, string password) { if (IsServiceInstalled()) { UninstallService(); } try { IntegratedServiceInstaller.Install(Assembly.GetExecutingAssembly().Location, PSService.PSServiceName, PSService.PSServiceDisplayName, PSService.PSServiceDescription, account, startMode, username, password); } catch { } }