def delete(self, start_driver): if not start_driver: return True if self.use_existing_service: return True if win32serviceutil.QueryServiceStatus( SERVICE_NAME)[1] != win32service.SERVICE_STOPPED: logger().warn("cannot delete service '{}' (not stopped)".format( SERVICE_NAME)) return False if logger().DEBUG: logger().log( "[helper] deleting service '{}'...".format(SERVICE_NAME)) try: win32serviceutil.RemoveService(SERVICE_NAME) if logger().DEBUG: logger().log( "[helper] service '{}' deleted".format(SERVICE_NAME)) except win32service.error as err: if logger().DEBUG: logger().warn("RemoveService failed: {} ({:d})".format( err.args[2], err.args[0])) return False return True
def stop_delete_service(service_name): ''' Checks if the service is installed as running. If it is running, it will stop it. If it is stopped, then it will delete it. ''' hscm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_ALL_ACCESS) try: win32service.OpenService(hscm, service_name, win32service.SERVICE_ALL_ACCESS) # Already installed status = win32serviceutil.QueryServiceStatus(service_name) if status[1] == 4: # Stop the service win32serviceutil.StopService(service_name) time.sleep(3) #delete the service win32serviceutil.RemoveService(service_name) time.sleep(3) return True except win32api.error, details: if details[0] != winerror.ERROR_SERVICE_DOES_NOT_EXIST: print service_name + "is not being installed properly but have other problem." return False else: # Service is not being installed and ready for fresh installtion return True
def UninstallDriver(driver_path, service_name, delete_file=False): """Unloads the driver and delete the driver file. Args: driver_path: Full path name to the driver file. service_name: Name of the service the driver is loaded as. delete_file: Should we delete the driver file after removing the service. Raises: OSError: On failure to uninstall or delete. """ try: win32serviceutil.StopService(service_name) except pywintypes.error as e: if e[0] not in [ winerror.ERROR_SERVICE_NOT_ACTIVE, winerror.ERROR_SERVICE_DOES_NOT_EXIST ]: raise OSError("Could not stop service: {0}".format(e)) try: win32serviceutil.RemoveService(service_name) except pywintypes.error as e: if e[0] != winerror.ERROR_SERVICE_DOES_NOT_EXIST: raise OSError("Could not remove service: {0}".format(e)) if delete_file: try: if os.path.exists(driver_path): os.remove(driver_path) except (OSError, IOError) as e: raise OSError("Driver deletion failed: " + str(e))
def do_remove(self, arg): if not shell.IsUserAnAdmin(): print(ERR_MSG_NOT_ADMIN) return status = self._get_service_status() if status is None: print('ERROR: Zope is not installed as a Windows service.') return elif status is not win32service.SERVICE_STOPPED: print('ERROR: Please stop the Windows service before ' 'removing it.') return ret_code = 0 name = self._get_service_name() try: win32serviceutil.RemoveService(name) print('Removed Windows Service "{}".'.format(name)) except pywintypes.error: ret_code = 1 traceback.print_exc() return ret_code
def removeService(service_name): # dirty remove of service try: status = win32serviceutil.QueryServiceStatus(service_name)[0] print "Service '%s' is installed !" % service_name print "status = %s" % status if status & win32service.SERVICE_START: try: print "Stop service '%s'" % service_name win32serviceutil.StopService(service_name) except: pass try: print "Remove service '%s'" % service_name win32serviceutil.RemoveService(service_name) except Exception, e: pass print "Waiting service to be removed..." while not status & win32service.SERVICE_STOP: print status try: status = win32serviceutil.QueryServiceStatus(service_name)[0] except: break time.sleep(1)
def deleteservice(service): try: win32serviceutil.RemoveService(service) # Delete service print "Services: {0} successfully deleted.".format(service) except pywintypes.error: logging.exception("Services: {0} unable to be deleted.".format(service)) print "Services: {0} unable to be deleted.".format(service)
def deleteservice(service): try: win32serviceutil.RemoveService(service) # Delete service print "Services: {0} successfully deleted.".format(service) except pywintypes.error as e: errors = (1060, 1062) if not any(error == e[0] for error in errors): logging.exception("Services: {0} unable to be deleted.".format(service)) print "Services: {0} unable to be deleted.".format(service)
def remove_service(): # get servive name name = WinService.name() try: wu.RemoveService(name) click.echo(f'UNINSTALLED: {name}') return 0 except ws.error as ex: raise click.ClickException(ex.strerror)
def uninstall(self): """Uninstalls the service so it can no longer be used (if it's installed). Returns: True when installing the service was a success and false when it failed. """ # Remove the service win32serviceutil.RemoveService(self.name)
def deleteservice(service): try: win32serviceutil.RemoveService(service) # Delete service print "Services: {0} successfully deleted.".format(service) except pywintypes.error as e: errors = ('does not exist', 'not been started') if not any(error in e[2] for error in errors): logging.exception( "Services: {0} unable to be deleted.".format(service)) print "Services: {0} unable to be deleted.".format(service)
def _RemoveService(service_name): try: win32serviceutil.RemoveService(service_name) logging.info("Service '%s' removed.", service_name) except pywintypes.error as e: if getattr(e, "winerror", None) == winerror.ERROR_SERVICE_DOES_NOT_EXIST: logging.debug("Tried to remove '%s', but the service is not installed.", service_name) else: logging.exception("Unable to remove service '%s':", service_name)
def Uninstall(cls): state = cls.__CurrentState() if state is None: print("Service %s is not installed." % cls._svc_name_) return if state not in [win32service.SERVICE_STOPPED]: win32serviceutil.StopServiceWithDeps(cls._svc_name_) win32serviceutil.RemoveService(cls._svc_name_) print("Service %s uninstalled successfully." % cls._svc_name_)
def delete_service(service): try: win32serviceutil.RemoveService(service) logger.info("Services: Succesfully removed service '{service}'".format( service=service)) except pywintypes.error as e: errors = (winerror.ERROR_SERVICE_DOES_NOT_EXIST, winerror.ERROR_SERVICE_NOT_ACTIVE) if not any(error == e.winerror for error in errors): logger.exception( "Services: Failed to remove service '{service}'".format( service=service))
def delete( self, start_driver ): if not start_driver: return True if self.use_existing_service: return True if win32serviceutil.QueryServiceStatus( SERVICE_NAME )[1] != win32service.SERVICE_STOPPED: if logger().DEBUG: logger().warn( "cannot delete service '%s' (not stopped)" % SERVICE_NAME ) return False if logger().DEBUG: logger().log( "[helper] deleting service '%s'..." % SERVICE_NAME ) try: win32serviceutil.RemoveService( SERVICE_NAME ) if logger().DEBUG: logger().log( "[helper] service '%s' deleted" % SERVICE_NAME ) except win32service.error, (hr, fn, msg): if logger().DEBUG: logger().warn( "RemoveService failed: %s (%d)" % (msg, hr) ) return False
def RunOnce(self): """Stop and remove an old unneeded service during installation.""" service_name = "My Old Service Name" try: win32serviceutil.StopService(service_name) except pywintypes.error as e: if e[0] not in [ winerror.ERROR_SERVICE_NOT_ACTIVE, winerror.ERROR_SERVICE_DOES_NOT_EXIST ]: raise OSError("Could not stop service: {0}".format(e)) try: win32serviceutil.RemoveService(service_name) except pywintypes.error as e: if e[0] != winerror.ERROR_SERVICE_DOES_NOT_EXIST: raise OSError("Could not remove service: {0}".format(e))
def setup(cls, cmd, user=None, password=None, startup='manual', cwd=None, wait=0): from gramex.config import app_log name, service_name = cls._svc_display_name_, cls._svc_name_ port = getattr(cls, '_svc_port_', None) if cwd is None: cwd = os.getcwd() info = (name, cwd, 'port %s' % port if port is not None else '') service_class = win32serviceutil.GetServiceClassString(cls) startup = cls.startup_map[startup] running = win32service.SERVICE_RUNNING if cmd[0] == 'install': win32serviceutil.InstallService( service_class, service_name, displayName=name, description=cls._svc_description_, startType=startup, userName=user, password=password) win32serviceutil.SetServiceCustomOption(cls._svc_name_, 'cwd', cwd) app_log.info('Installed service. %s will run from %s %s' % info) elif cmd[0] in {'update', 'change'}: win32serviceutil.ChangeServiceConfig( service_class, service_name, displayName=name, description=cls._svc_description_, startType=startup, userName=user, password=password) win32serviceutil.SetServiceCustomOption(cls._svc_name_, 'cwd', cwd) app_log.info('Updated service. %s will run from %s %s' % info) elif cmd[0] in {'remove', 'uninstall'}: try: win32serviceutil.StopService(service_name) except pywintypes.error as e: if e.args[0] != winerror.ERROR_SERVICE_NOT_ACTIVE: raise win32serviceutil.RemoveService(service_name) app_log.info('Removed service. %s ran from %s %s' % info) elif cmd[0] == 'start': win32serviceutil.StartService(service_name, cmd[1:]) if wait: win32serviceutil.WaitForServiceStatus(service_name, running, wait) app_log.info('Started service %s at %s %s' % info) elif cmd[0] == 'stop': if wait: win32serviceutil.StopServiceWithDeps(service_name, waitSecs=wait) else: win32serviceutil.StopService(service_name) app_log.info('Stopped service %s at %s %s' % info) elif cmd[0]: app_log.error('Unknown command: %s' % cmd[0])
def w32_uninstall_svc(): '''Uninstall (remove) Windows Ramona Service''' import logging L = logging.getLogger('winsvc') cls = w32_ramona_service if cls._svc_name_ is None: cls.configure() scvType, svcState, svcControls, err, svcErr, svcCP, svcWH = win32serviceutil.QueryServiceStatus( cls._svc_name_) if svcState == win32service.SERVICE_RUNNING: L.debug("Service {0} is stopping ...".format(cls._svc_name_)) win32serviceutil.StopService(cls._svc_name_) L.debug("Service {0} is stopped.".format(cls._svc_name_)) win32serviceutil.RemoveService(cls._svc_name_) return cls
def remove(cls): win32serviceutil.RemoveService(cls._svc_name_)
None, k._svc_name_, svc_display_name, exeName=sys.executable, userName=userName, password=password, startType=startType, bRunInteractive=bRunInteractive, serviceDeps=svc_deps, description=getattr(k, "_svc_description_", None), ) done = True if do_remove: for k in service_klasses: win32serviceutil.RemoveService(k._svc_name_) done = True if done: sys.exit(0) else: usage() print "Connecting to the Service Control Manager" servicemanager.StartServiceCtrlDispatcher() elif cmdline_style == "pywin32": assert len(service_klasses) == 1, "Can only handle 1 service!" k = service_klasses[0] if len(sys.argv) == 1: try:
def removesvc(service): win32serviceutil.RemoveService(service._svc_name_)
def onok(self, event): if self.telebox.IsChecked(): self.telekeypath = r'SOFTWARE\Policies\Microsoft\Windows\DataCollection' # Path to Telemetry key self.telekey2path = r'SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\DataCollection' # 2nd path try: self.telekey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, self.telekeypath, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(self.telekey, "AllowTelemetry", 0, _winreg.REG_SZ, "0") # Disable Telemetry _winreg.CloseKey(self.telekey) print "Telemetry key succesfully modified." except WindowsError: print "Unable to modify Telemetry key. Deleted, or is the program not elevated? Trying another method" try: self.telekey2 = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, self.telekey2path, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(self.telekey2, "AllowTelemetry", 0, _winreg.REG_SZ, "0") # Disable Telemetry _winreg.CloseKey(self.telekey2) print "2nd Telemetry key succesfully modified." except WindowsError: print "Unable to modify 2nd Telemetry key. Deleted, or is the program not elevated?" if self.diagbox.IsChecked(): self.logfile = os.path.join(os.environ['SYSTEMDRIVE'], '\\ProgramData\\Microsoft\\Diagnosis\\ETLLogs\\AutoLogger\\AutoLogger-Diagtrack-Listener.etl') try: win32serviceutil.StopService('Diagnostics Tracking Service') # Stop Diagnostics Tracking Service print "Stopping DiagTrack service." except pywintypes.error: print "Couldn't stop DiagTrack service. Deleted, or is the program not elevated?" try: open(self.logfile).close() # Clear the AutoLogger file subprocess.Popen( ["echo", "y|cacls", self.logfile, "/d", "SYSTEM"], shell=True) # Prevent modification to file print "DiagTrack log succesfully cleared and locked." except IOError: print "Unable to clear DiagTrack log. Deleted, or is the program not elevated?" if self.hostbox.IsChecked(): self.MSHosts = ['adnxs.com', 'c.msn.com', 'g.msn.com', 'h1.msn.com', 'msedge.net', 'rad.msn.com', 'ads.msn.com', 'adnexus.net', 'ac3.msn.com', 'c.atdmt.com', 'm.adnxs.com', 'rad.msn.com', 'sO.2mdn.net', 'ads1.msn.com', 'ec.atdmt.com', 'flex.msn.com', 'rad.live.com', 'ui.skype.com', 'msftncsi.com', 'a-msedge.net', 'a.rad.msn.com', 'b.rad.msn.com', 'cdn.atdmt.com', 'm.hotmail.com', 'ads1.msads.net', 'a.ads1.msn.com', 'a.ads2.msn.com', 'apps.skype.com', 'b.ads1.msn.com', 'view.atdmt.com', 'watson.live.com', 'preview.msn.com', 'aidps.atdmt.com', 'preview.msn.com', 'static.2mdn.net', 'a.ads2.msads.net', 'b.ads2.msads.net', 'db3aqu.atdmt.com', 'secure.adnxs.com', 'www.msftncsi.com', 'cs1.wpc.v0cdn.net', 'live.rads.msn.com', 'ad.doubleclick.net', 'bs.serving-sys.com', 'a-0001.a-msedge.net', 'pricelist.skype.com', 'a-0001.a-msedge.net', 'a-0002.a-msedge.net', 'a-0003.a-msedge.net', 'a-0004.a-msedge.net', 'a-0005.a-msedge.net', 'a-0006.a-msedge.net', 'a-0007.a-msedge.net', 'a-0008.a-msedge.net', 'a-0009.a-msedge.net', 'choice.microsoft.com', 'watson.microsoft.com', 'feedback.windows.com', 'aka-cdn-ns.adtech.de', 'cds26.ams9.msecn.net', 'lb1.www.ms.akadns.net', 'corp.sts.microsoft.com', 'az361816.vo.msecnd.net', 'az512334.vo.msecnd.net', 'telemetry.microsoft.com', 'msntest.serving-sys.com', 'secure.flashtalking.com', 'telemetry.appex.bing.net', 'pre.footprintpredict.com', 'pre.footprintpredict.com', 'vortex.data.microsoft.com', 'statsfe2.ws.microsoft.com', 'statsfe1.ws.microsoft.com', 'df.telemetry.microsoft.com', 'oca.telemetry.microsoft.com', 'sqm.telemetry.microsoft.com', 'telemetry.urs.microsoft.com', 'survey.watson.microsoft.com', 'compatexchange.cloudapp.net', 'feedback.microsoft-hohm.com', 's.gateway.messenger.live.com', 'vortex-win.data.microsoft.com', 'feedback.search.microsoft.com', 'schemas.microsoft.akadns.net ', 'watson.telemetry.microsoft.com', 'choice.microsoft.com.nsatc.net', 'wes.df.telemetry.microsoft.com', 'sqm.df.telemetry.microsoft.com', 'settings-win.data.microsoft.com', 'redir.metaservices.microsoft.com', 'i1.services.social.microsoft.com', 'vortex-sandbox.data.microsoft.com', 'diagnostics.support.microsoft.com', 'watson.ppe.telemetry.microsoft.com', 'msnbot-65-55-108-23.search.msn.com', 'telecommand.telemetry.microsoft.com', 'settings-sandbox.data.microsoft.com', 'sls.update.microsoft.com.akadns.net', 'fe2.update.microsoft.com.akadns.net', 'vortex-bn2.metron.live.com.nsatc.net', 'vortex-cy2.metron.live.com.nsatc.net', 'oca.telemetry.microsoft.com.nsatc.net', 'sqm.telemetry.microsoft.com.nsatc.net', 'reports.wes.df.telemetry.microsoft.com', 'corpext.msitadfs.glbdns2.microsoft.com', 'services.wes.df.telemetry.microsoft.com', 'watson.telemetry.microsoft.com.nsatc.net', 'statsfe2.update.microsoft.com.akadns.net', 'i1.services.social.microsoft.com.nsatc.net', 'telecommand.telemetry.microsoft.com.nsatc.net'] self.IP = '0.0.0.0 ' self.MSHosts2 = [self.IP + x for x in self.MSHosts] self.hostslocation = os.path.join(os.environ['SYSTEMROOT'], 'System32\\drivers\\etc\\hosts') try: with open(self.hostslocation, 'ab') as f: f.write('\n' + '\n'.join(self.MSHosts2)) print "Domains successfully appended to HOSTS file." except WindowsError: print "Could not access HOSTS file. Is the program not elevated?" if self.onedrivebox.IsChecked(): self.onedkeypath = r'SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\OneDrive' # Path to OneDrive key try: self.onedkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, self.onedkeypath, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(self.onedkey, "DisableFileSyncNGSC", 0, _winreg.REG_DWORD, 1) # Disable Telemetry _winreg.CloseKey(self.onedkey) print "OneDrive key succesfully modified." except WindowsError: print "Unable to modify OneDrive key. Deleted, or is the program not elevated?" if self.servicerad.Selection == 1 and self.servicebox.IsChecked(): try: win32serviceutil.RemoveService('dmwappushsvc') # Delete dmwappushsvc print "dmwappushsvc successfully deleted." except pywintypes.error: print "dmwappushsvc unable to be deleted. Deleted already, or is the program not elevated?" try: win32serviceutil.RemoveService('Diagnostics Tracking Service') # Delete the DiagnosticsTracking Service print "Diagnostics Tracking Service successfully deleted." except pywintypes.error: print "Diagnostics Tracking Service unable to be deleted. Deleted already, or is the program not elevated?" elif self.servicerad.Selection == 0 and self.servicebox.IsChecked(): self.diagkeypath = r'SYSTEM\CurrentControlSet\Services\DiagTrack' self.dmwakeypath = r'SYSTEM\CurrentControlSet\Services\dmwappushsvc' try: self.diagkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, self.diagkeypath, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(self.diagkey, "Start", 0, _winreg.REG_DWORD, 0x0000004) _winreg.CloseKey(self.diagkey) except WindowsError: print "Unable to modify DiagTrack key. Deleted, or is the program not elevated?" try: self.dmwakey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, self.dmwakeypath, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(self.dmwakey, "Start", 0, _winreg.REG_DWORD, 0x0000004) _winreg.CloseKey(self.dmwakey) print "dmwappushsvc key successfully modified" except WindowsError: print "Unable to modify dmwappushsvc key. Deleted, or is the program not elevated?" try: win32serviceutil.StopService('Diagnostics Tracking Service') # Disable Diagnostics Tracking Service print "Diagnostics Tracking Service successfully stopped" except pywintypes.error: print "Diagnostics Tracking Service unable to be stopped. Deleted, or is the program not elevated?" try: win32serviceutil.StopService('dmwappushsvc') # Disable dmwappushsvc print "dmwappushsvc successfully stopped" except pywintypes.error: print "dmwappushsvc unable to be stopped. Deleted, or is the program not elevated?" print "Done. You can close this window after reading the log."
def UnregisterDriver(self): try: win32serviceutil.RemoveService(self.name) except: pass
def remove_serial_mux_service(self, name): self.stop_service(name) win32serviceutil.RemoveService(self._make_service_name(name))
def removeService(): win32serviceutil.RemoveService(NVDAService._svc_name_)
def __delete(args): if sys.platform.startswith('win'): w32scu.RemoveService(serviceName=args.name)
if HOST_INFO.isWindows(): import win32service import win32serviceutil import pywintypes import _winreg import win32api, win32pdhutil, win32con def __install_automation_win32(): # Try to stop and remove any old service first try: win32serviceutil.StopService(SERVICE_NAME) except pywintypes.error, err: pass try: win32serviceutil.RemoveService(SERVICE_NAME) except pywintypes.error, err: pass service_rnr = os.sep.join([LIBDIR, 'ServiceRunner.py']) subprocess.check_call([ sys.executable, service_rnr, '--interactive', '--startup', 'auto', 'install' ]) subprocess.check_call([sys.executable, service_rnr, 'start']) print "success!" # Install the Tray Icon print "\n>> Installing Automation Tray Icon ... " tray_icon_path = '"' + os.path.join(BASEDIR, 'lib', 'TrayIcon.pyw') + '"'
def deleteservice(service): try: win32serviceutil.RemoveService(service) # Delete service print "%s successfully deleted." % service except pywintypes.error: print "%s unable to be deleted. Deleted already, or is the program not elevated?" % service
def delete(self): try: win32serviceutil.RemoveService(self.svc_name) logger.info("service '%s' removed", self.svc_name) except win32service.error as exc: logger.info("error removing service: %s (%d)", exc.strerror, exc.winerror)