Python win32api.GetLastError() Examples
The following are 22
code examples of win32api.GetLastError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32api
, or try the search function
.
Example #1
Source File: NamedMutex.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def release(self): # unlock assert self._mylock if os.name == 'nt': win32event.ReleaseMutex(self._mutex) # Error code 123? #lasterror = win32api.GetLastError() #if lasterror != 0: # raise IOError( _("Could not release mutex %s due to " # "error windows code %d.") % # (self._name,lasterror) ) elif os.name == 'posix': self._mylock = False if not os.path.exists(self._path): raise IOError( _("Non-existent file: %s") % self._path ) flock( self._mutex.fileno(), fcntl.LOCK_UN ) self._mutex.close()
Example #2
Source File: Mutex.py From Crypter with GNU General Public License v3.0 | 6 votes |
def __acquire(self): ''' Attempts to acquire the mutex @raise MutexAlreadyAcquired ''' mutex = win32event.CreateMutex(None, 1, self.MUTEX_NAME) if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS: raise MutexAlreadyAcquired() return mutex # ================================================================ # = MutexAlreadyAcquired Exception Class # ===============================================================
Example #3
Source File: winapi.py From gui-o-matic with GNU Lesser General Public License v3.0 | 6 votes |
def update( self, window, hdc ): rect = self.rect or window.get_client_region() try: background = self.background or win32gui.GetPixel( hdc, rect[0], rect[1] ) self.last_background = background except: print "FIXME: Figure out why GetPixel( hdc, 0, 0 ) is failing..." #traceback.print_exc() #print "GetLastError() => {}".format( win32api.GetLastError() ) background = self.last_background color = ((background >> 0 ) & 255, (background >> 8 ) & 255, (background >> 16 ) & 255, 255) size = ( rect[2] - rect[0], rect[3] - rect[1] ) combined = self.render( size, color ) self.image = Image.Bitmap( combined )
Example #4
Source File: win32.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def stop(self): if not self.is_set: self.bus.log('Handler for console events already off.', level=40) return try: result = win32api.SetConsoleCtrlHandler(self.handle, 0) except ValueError: # "ValueError: The object has not been registered" result = 1 if result == 0: self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Removed handler for console events.', level=40) self.is_set = False
Example #5
Source File: win32.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def stop(self): if not self.is_set: self.bus.log('Handler for console events already off.', level=40) return try: result = win32api.SetConsoleCtrlHandler(self.handle, 0) except ValueError: # "ValueError: The object has not been registered" result = 1 if result == 0: self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Removed handler for console events.', level=40) self.is_set = False
Example #6
Source File: win32.py From bazarr with GNU General Public License v3.0 | 6 votes |
def stop(self): if not self.is_set: self.bus.log('Handler for console events already off.', level=40) return try: result = win32api.SetConsoleCtrlHandler(self.handle, 0) except ValueError: # "ValueError: The object has not been registered" result = 1 if result == 0: self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Removed handler for console events.', level=40) self.is_set = False
Example #7
Source File: win32.py From opsbro with MIT License | 6 votes |
def stop(self): if not self.is_set: self.bus.log('Handler for console events already off.', level=40) return try: result = win32api.SetConsoleCtrlHandler(self.handle, 0) except ValueError: # "ValueError: The object has not been registered" result = 1 if result == 0: self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Removed handler for console events.', level=40) self.is_set = False
Example #8
Source File: winpty.py From marsnake with GNU General Public License v3.0 | 6 votes |
def start(self, cmd): sAttr = win32security.SECURITY_ATTRIBUTES() sAttr.bInheritHandle = True stdout_r, stdout_w = win32pipe.CreatePipe(sAttr,0) stdin_r, stdin_w = win32pipe.CreatePipe(sAttr,0) self.read_handle=stdout_r self.write_handle=stdout_w self.stdin_write=stdin_w si = win32process.STARTUPINFO() si.dwFlags = win32process.STARTF_USESHOWWINDOW | win32process.STARTF_USESTDHANDLES si.wShowWindow = win32con.SW_HIDE si.hStdInput = stdin_r # file descriptor of origin stdin si.hStdOutput = stdout_w si.hStdError = stdout_w hProcess, hThread, dwProcessID, dwThreadID = win32process.CreateProcess(None,"cmd", None, None, True, win32process.CREATE_NEW_CONSOLE, None, None, si) self.dwProcessID=dwProcessID self.hProcess=hProcess sleep(0.5) if self.hProcess == 0: DebugOutput("Start Process Fail:{:d}".format(win32api.GetLastError())) DebugOutput('[*] pid: {:x}'.format(self.dwProcessID)) self.Console_hwnd = get_hwnds_for_pid(self.dwProcessID) if len(self.Console_hwnd)==0: raise Exception("Fail to run,No Process!") DebugOutput('[*] hwnd:{:x}'.format(self.Console_hwnd[0]))
Example #9
Source File: win32.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def stop(self): if not self.is_set: self.bus.log('Handler for console events already off.', level=20) return try: result = win32api.SetConsoleCtrlHandler(self.handle, 0) except ValueError: # "ValueError: The object has not been registered" result = 1 if result == 0: self.bus.log('Could not remove SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Removed handler for console events.', level=20) self.is_set = False
Example #10
Source File: win32.py From opsbro with MIT License | 5 votes |
def start(self): if self.is_set: self.bus.log('Handler for console events already set.', level=40) return result = win32api.SetConsoleCtrlHandler(self.handle, 1) if result == 0: self.bus.log('Could not SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Set handler for console events.', level=40) self.is_set = True
Example #11
Source File: sendinput.py From dragonfly with GNU Lesser General Public License v3.0 | 5 votes |
def send_input_array(input_array): length = len(input_array) assert length >= 0 size = sizeof(input_array[0]) ptr = pointer(input_array) count_inserted = windll.user32.SendInput(length, ptr, size) if count_inserted != length: last_error = win32api.GetLastError() message = win32api.FormatMessage(last_error) raise ValueError("windll.user32.SendInput(): %s" % (message))
Example #12
Source File: IPC.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def create(self): obtain_mutex = 1 mutex = win32event.CreateMutex(None, obtain_mutex, app_name) # prevent the PyHANDLE from going out of scope, ints are fine self.mutex = int(mutex) mutex.Detach() lasterror = win32api.GetLastError() if lasterror == winerror.ERROR_ALREADY_EXISTS: takeover = 0 try: # if the mutex already exists, discover which port to connect to. # if something goes wrong with that, tell us to take over the # role of master takeover = self.discover_sic_socket() except: pass if not takeover: raise BTFailure(_("Global mutex already created.")) self.master = 1 # lazy free port code port_limit = 50000 while self.port < port_limit: try: controlsocket = self.rawserver.create_serversocket(self.port, '127.0.0.1') self.controlsocket = controlsocket break except socket.error, e: self.port += 1
Example #13
Source File: IPC.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def __init__(self): obtain_mutex = False self.mutex = win32event.CreateMutex(None, obtain_mutex, app_name) self.lasterror = win32api.GetLastError()
Example #14
Source File: win32.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def start(self): if self.is_set: self.bus.log('Handler for console events already set.', level=20) return result = win32api.SetConsoleCtrlHandler(self.handle, 1) if result == 0: self.bus.log('Could not SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Set handler for console events.', level=20) self.is_set = True
Example #15
Source File: wts.py From code with MIT License | 5 votes |
def __init__(self, func=None, err=0): if err: self.err = err else: self.err = win32api.GetLastError() self.message = win32api.FormatMessageW(self.err) self.args = (self.err, func, self.message)
Example #16
Source File: win32.py From bazarr with GNU General Public License v3.0 | 5 votes |
def start(self): if self.is_set: self.bus.log('Handler for console events already set.', level=40) return result = win32api.SetConsoleCtrlHandler(self.handle, 1) if result == 0: self.bus.log('Could not SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Set handler for console events.', level=40) self.is_set = True
Example #17
Source File: win32.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def start(self): if self.is_set: self.bus.log('Handler for console events already set.', level=40) return result = win32api.SetConsoleCtrlHandler(self.handle, 1) if result == 0: self.bus.log('Could not SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Set handler for console events.', level=40) self.is_set = True
Example #18
Source File: sendinput.py From dragonfly with GNU Lesser General Public License v3.0 | 5 votes |
def send_input_array(input_array): length = len(input_array) assert length >= 0 size = sizeof(input_array[0]) ptr = pointer(input_array) count_inserted = windll.user32.SendInput(length, ptr, size) if count_inserted != length: last_error = win32api.GetLastError() message = win32api.FormatMessage(last_error) raise ValueError("windll.user32.SendInput(): %s" % (message))
Example #19
Source File: win32.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def start(self): if self.is_set: self.bus.log('Handler for console events already set.', level=40) return result = win32api.SetConsoleCtrlHandler(self.handle, 1) if result == 0: self.bus.log('Could not SetConsoleCtrlHandler (error %r)' % win32api.GetLastError(), level=40) else: self.bus.log('Set handler for console events.', level=40) self.is_set = True
Example #20
Source File: test_win32api.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_last_error(self): for x in (0, 1, -1, winerror.TRUST_E_PROVIDER_UNKNOWN): win32api.SetLastError(x) self.failUnlessEqual(x, win32api.GetLastError())
Example #21
Source File: RDP.py From XFLTReaT with MIT License | 5 votes |
def OpenDynamicChannel(self, channelname, priority): # C+Python = OMG... global pywintypes import ctypes.wintypes import ctypes import pywintypes import win32api wts = ctypes.windll.LoadLibrary("Wtsapi32.dll") hWTSHandle = wts.WTSVirtualChannelOpenEx(0xFFFFFFFF, channelname, 0x00000001 | priority) if not hWTSHandle: common.internal_print("Opening channel failed: {0}".format(win32api.GetLastError()), -1) return None WTSVirtualFileHandle = 1 vcFileHandlePtr = ctypes.pointer(ctypes.c_int()) length = ctypes.c_ulong(0) if not wts.WTSVirtualChannelQuery(hWTSHandle, WTSVirtualFileHandle, ctypes.byref(vcFileHandlePtr), ctypes.byref(length)): wts.WTSVirtualChannelClose(hWTSHandle) common.internal_print("Channel query: {0}".format(win32api.GetLastError()), -1) return None common.internal_print("Connected to channel: {0}".format(channelname)) return pywintypes.HANDLE(vcFileHandlePtr.contents.value)
Example #22
Source File: singleinstance.py From Email_My_PC with MIT License | 5 votes |
def __init__(self): self.mutexname = "testmutex_{D0E858DF-985E-4907-B7FB-8D732C3FC3B9}" self.mutex = CreateMutex(None, False, self.mutexname) self.lasterror = GetLastError()