public void UnconfigureService() { if (!_windowsServiceHelper.IsRunningInElevatedMode()) { Trace.Error("Needs Administrator privileges for unconfigure windows service agent."); throw new SecurityException(StringUtil.Loc("NeedAdminForUnconfigWinServiceAgent")); } string serviceConfigPath = HostContext.GetConfigFile(WellKnownConfigFile.Service); string serviceName = File.ReadAllText(serviceConfigPath); if (_windowsServiceHelper.IsServiceExists(serviceName)) { _windowsServiceHelper.StopService(serviceName); _windowsServiceHelper.UninstallService(serviceName); // Delete local group we created during configure. string agentRoot = HostContext.GetDirectory(WellKnownDirectory.Root); string workFolder = HostContext.GetDirectory(WellKnownDirectory.Work); _windowsServiceHelper.RevokeDirectoryPermissionForAccount(new[] { agentRoot, workFolder }); // Remove registry key only on Windows _windowsServiceHelper.DeleteVstsAgentRegistryKey(); } IOUtil.DeleteFile(serviceConfigPath); }
public void Unconfigure() { if (!_windowsServiceHelper.IsRunningInElevatedMode()) { Trace.Error("Needs Administrator privileges to unconfigure an agent running with AutoLogon capability."); throw new SecurityException(StringUtil.Loc("NeedAdminForAutologonRemoval")); } var autoLogonSettings = _store.GetAutoLogonSettings(); _autoLogonRegManager.ResetRegistrySettings(autoLogonSettings.UserDomainName, autoLogonSettings.UserName); _windowsServiceHelper.ResetAutoLogonPassword(); // Delete local group we created during configure. string agentRoot = HostContext.GetDirectory(WellKnownDirectory.Root); string workFolder = HostContext.GetDirectory(WellKnownDirectory.Work); _windowsServiceHelper.RevokeDirectoryPermissionForAccount(new[] { agentRoot, workFolder }); Trace.Info("Deleting the autologon settings now."); _store.DeleteAutoLogonSettings(); Trace.Info("Successfully deleted the autologon settings."); }
public void UnconfigureService() { if (!_windowsServiceHelper.IsRunningInElevatedMode()) { Trace.Error("Needs Administrator privileges for unconfigure windows service runner."); throw new SecurityException("Needs Administrator privileges for unconfiguring runner that running as windows service."); } string serviceConfigPath = HostContext.GetConfigFile(WellKnownConfigFile.Service); string serviceName = File.ReadAllText(serviceConfigPath); if (_windowsServiceHelper.IsServiceExists(serviceName)) { _windowsServiceHelper.StopService(serviceName); _windowsServiceHelper.UninstallService(serviceName); // Delete local group we created during configure. string runnerRoot = HostContext.GetDirectory(WellKnownDirectory.Root); string workFolder = HostContext.GetDirectory(WellKnownDirectory.Work); _windowsServiceHelper.RevokeDirectoryPermissionForAccount(new[] { runnerRoot, workFolder }); } IOUtil.DeleteFile(serviceConfigPath); }