def processInterrupt(uPid): """ The Windows version of base.processInterrupt Note! This doesn't work terribly well with a lot of processes. """ try: win32console.GenerateConsoleCtrlEvent(win32con.CTRL_BREAK_EVENT, uPid) #GenerateConsoleCtrlEvent = ctypes.windll.kernel32.GenerateConsoleCtrlEvent #rc = GenerateConsoleCtrlEvent(1, uPid); #reporter.log('GenerateConsoleCtrlEvent -> %s' % (rc,)); fRc = True except: reporter.logXcpt('uPid=%s' % (uPid, )) fRc = False return fRc
def make_input_key(c, control_key_state=None): kc = win32console.PyINPUT_RECORDType(win32console.KEY_EVENT) kc.KeyDown = True kc.RepeatCount = 1 cnum = ord(c) if cnum == 3: pid_list = win32console.GetConsoleProcessList() win32console.GenerateConsoleCtrlEvent(win32con.CTRL_C_EVENT, 0) return else: kc.Char = unicode(c) if str(cnum) in CONQUE_WINDOWS_VK: kc.VirtualKeyCode = CONQUE_WINDOWS_VK[str(cnum)] else: kc.VirtualKeyCode = ctypes.windll.user32.VkKeyScanA(cnum) #kc.VirtualKeyCode = ctypes.windll.user32.VkKeyScanA(cnum+96) #kc.ControlKeyState = win32con.LEFT_CTRL_PRESSED return kc
def SvcStop(self): self.running = False self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) try: pids = win32console.GetConsoleProcessList() except: pids = tuple() try: pid = self.process.pid if not pid in pids: win32console.AttachConsole(self.process.pid) win32console.GenerateConsoleCtrlEvent(win32console.CTRL_C_EVENT, self.process.pid) if not pid in pids: win32console.FreeConsole() except: servicemanager.LogErrorMsg(traceback.format_exc())
def processInterrupt(uPid): """ Sends a SIGINT or equivalent to interrupt the specified process. Returns True on success, False on failure. On Windows hosts this may not work unless the process happens to be a process group leader. """ if sys.platform == 'win32': try: win32console.GenerateConsoleCtrlEvent(win32con.CTRL_BREAK_EVENT, uPid); # pylint fRc = True; except: fRc = False; else: try: os.kill(uPid, signal.SIGINT); fRc = True; except: fRc = False; return fRc;