Beispiel #1
0
        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 override void UnconfigureService()
        {
            string serviceConfigPath = IOUtil.GetServiceConfigFilePath();
            string serviceName       = File.ReadAllText(serviceConfigPath);

            if (CheckServiceExists(serviceName))
            {
                StopService();
                UninstallService(serviceName);

                // Remove registry key only on Windows
                _windowsServiceHelper.DeleteVstsAgentRegistryKey();
            }
            IOUtil.Delete(serviceConfigPath, default(CancellationToken));
        }
        public void UnconfigureService()
        {
            string serviceConfigPath = IOUtil.GetServiceConfigFilePath();
            string serviceName       = File.ReadAllText(serviceConfigPath);

            if (_windowsServiceHelper.IsServiceExists(serviceName))
            {
                _windowsServiceHelper.StopService(serviceName);
                _windowsServiceHelper.UninstallService(serviceName);

                // Delete local group we created during confiure.
                RevokeDirectoryPermissionForAccount();

                // Remove registry key only on Windows
                _windowsServiceHelper.DeleteVstsAgentRegistryKey();
            }

            IOUtil.DeleteFile(serviceConfigPath);
        }