Python win32api.FormatMessage() Examples

The following are 30 code examples of win32api.FormatMessage(). 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: win32util.py    From PhonePi_SampleServer with MIT License 6 votes vote down vote up
def fromEnvironment(cls):
        """
        Get as many of the platform-specific error translation objects as
        possible and return an instance of C{cls} created with them.
        """
        try:
            from ctypes import WinError
        except ImportError:
            WinError = None
        try:
            from win32api import FormatMessage
        except ImportError:
            FormatMessage = None
        try:
            from socket import errorTab
        except ImportError:
            errorTab = None
        return cls(WinError, FormatMessage, errorTab) 
Example #2
Source File: win32.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def fromEnvironment(cls):
        """
        Get as many of the platform-specific error translation objects as
        possible and return an instance of C{cls} created with them.
        """
        try:
            from ctypes import WinError
        except ImportError:
            WinError = None
        try:
            from win32api import FormatMessage
        except ImportError:
            FormatMessage = None
        try:
            from socket import errorTab
        except ImportError:
            errorTab = None
        return cls(WinError, FormatMessage, errorTab) 
Example #3
Source File: win32util.py    From satori with Apache License 2.0 6 votes vote down vote up
def fromEnvironment(cls):
        """
        Get as many of the platform-specific error translation objects as
        possible and return an instance of C{cls} created with them.
        """
        try:
            from ctypes import WinError
        except ImportError:
            WinError = None
        try:
            from win32api import FormatMessage
        except ImportError:
            FormatMessage = None
        try:
            from socket import errorTab
        except ImportError:
            errorTab = None
        return cls(WinError, FormatMessage, errorTab) 
Example #4
Source File: test_strerror.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def test_correctLookups(self):
        """
        Given a known-good errno, make sure that formatMessage gives results
        matching either C{socket.errorTab}, C{ctypes.WinError}, or
        C{win32api.FormatMessage}.
        """
        acceptable = [socket.errorTab[ECONNABORTED]]
        try:
            from ctypes import WinError
            acceptable.append(WinError(ECONNABORTED).strerror)
        except ImportError:
            pass
        try:
            from win32api import FormatMessage
            acceptable.append(FormatMessage(ECONNABORTED))
        except ImportError:
            pass

        self.assertIn(formatError(ECONNABORTED), acceptable) 
Example #5
Source File: test_strerror.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def test_correctLookups(self):
        """
        Given a known-good errno, make sure that formatMessage gives results
        matching either C{socket.errorTab}, C{ctypes.WinError}, or
        C{win32api.FormatMessage}.
        """
        acceptable = [socket.errorTab[ECONNABORTED]]
        try:
            from ctypes import WinError
            acceptable.append(WinError(ECONNABORTED).strerror)
        except ImportError:
            pass
        try:
            from win32api import FormatMessage
            acceptable.append(FormatMessage(ECONNABORTED))
        except ImportError:
            pass

        self.assertIn(formatError(ECONNABORTED), acceptable) 
Example #6
Source File: win32.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def fromEnvironment(cls):
        """
        Get as many of the platform-specific error translation objects as
        possible and return an instance of C{cls} created with them.
        """
        try:
            from ctypes import WinError
        except ImportError:
            WinError = None
        try:
            from win32api import FormatMessage
        except ImportError:
            FormatMessage = None
        try:
            from socket import errorTab
        except ImportError:
            errorTab = None
        return cls(WinError, FormatMessage, errorTab) 
Example #7
Source File: mem.py    From Fastir_Collector with GNU General Public License v3.0 6 votes vote down vote up
def _GetProcessModules(self, ProcessID, isPrint):
        me32 = MODULEENTRY32()
        me32.dwSize = sizeof(MODULEENTRY32)
        hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcessID)

        ret = Module32First(hModuleSnap, pointer(me32))
        if ret == 0:
            errCode = GetLastError()
            self.logger.warn('GetProcessModules() Error on Module32First[%d] with PID : %d' % (errCode, ProcessID))
            self.logger.warn(win32api.FormatMessage(errCode))
            CloseHandle(hModuleSnap)
            return []

        modules = []
        while ret:
            if isPrint:
                self.logger.info("   executable	 = %s" % me32.szExePath)
            modules.append(me32.szExePath)

            ret = Module32Next(hModuleSnap, pointer(me32))
        CloseHandle(hModuleSnap)
        return modules 
Example #8
Source File: win32.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def fromEnvironment(cls):
        """
        Get as many of the platform-specific error translation objects as
        possible and return an instance of C{cls} created with them.
        """
        try:
            from ctypes import WinError
        except ImportError:
            WinError = None
        try:
            from win32api import FormatMessage
        except ImportError:
            FormatMessage = None
        try:
            from socket import errorTab
        except ImportError:
            errorTab = None
        return cls(WinError, FormatMessage, errorTab) 
Example #9
Source File: test_strerror.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_correctLookups(self):
        """
        Given an known-good errno, make sure that formatMessage gives results
        matching either C{socket.errorTab}, C{ctypes.WinError}, or
        C{win32api.FormatMessage}.
        """
        acceptable = [socket.errorTab[ECONNABORTED]]
        try:
            from ctypes import WinError
            acceptable.append(WinError(ECONNABORTED)[1])
        except ImportError:
            pass
        try:
            from win32api import FormatMessage
            acceptable.append(FormatMessage(ECONNABORTED))
        except ImportError:
            pass

        self.assertIn(formatError(ECONNABORTED), acceptable) 
Example #10
Source File: win32util.py    From PokemonGo-DesktopMap with MIT License 6 votes vote down vote up
def fromEnvironment(cls):
        """
        Get as many of the platform-specific error translation objects as
        possible and return an instance of C{cls} created with them.
        """
        try:
            from ctypes import WinError
        except ImportError:
            WinError = None
        try:
            from win32api import FormatMessage
        except ImportError:
            FormatMessage = None
        try:
            from socket import errorTab
        except ImportError:
            errorTab = None
        return cls(WinError, FormatMessage, errorTab) 
Example #11
Source File: win32util.py    From PokemonGo-DesktopMap with MIT License 6 votes vote down vote up
def fromEnvironment(cls):
        """
        Get as many of the platform-specific error translation objects as
        possible and return an instance of C{cls} created with them.
        """
        try:
            from ctypes import WinError
        except ImportError:
            WinError = None
        try:
            from win32api import FormatMessage
        except ImportError:
            FormatMessage = None
        try:
            from socket import errorTab
        except ImportError:
            errorTab = None
        return cls(WinError, FormatMessage, errorTab) 
Example #12
Source File: test_strerror.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def test_fromEnvironment(self):
        """
        L{_ErrorFormatter.fromEnvironment} should create an L{_ErrorFormatter}
        instance with attributes populated from available modules.
        """
        formatter = _ErrorFormatter.fromEnvironment()

        if formatter.winError is not None:
            from ctypes import WinError
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                WinError(self.probeErrorCode)[1])
            formatter.winError = None

        if formatter.formatMessage is not None:
            from win32api import FormatMessage
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                FormatMessage(self.probeErrorCode))
            formatter.formatMessage = None

        if formatter.errorTab is not None:
            from socket import errorTab
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                errorTab[self.probeErrorCode]) 
Example #13
Source File: win32.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def __init__(self, WinError, FormatMessage, errorTab):
        self.winError = WinError
        self.formatMessage = FormatMessage
        self.errorTab = errorTab 
Example #14
Source File: sendinput.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #15
Source File: win32util.py    From PhonePi_SampleServer with MIT License 5 votes vote down vote up
def __init__(self, WinError, FormatMessage, errorTab):
        self.winError = WinError
        self.formatMessage = FormatMessage
        self.errorTab = errorTab 
Example #16
Source File: windows_event_log_monitor.py    From scalyr-agent-2 with Apache License 2.0 5 votes vote down vote up
def _open_remote_session_if_necessary(self, server, config):
        """
            Opens a session to a remote server if `server` is not localhost or None
            @param server: string containing the server to connect to (can be None)
            @param config: a log config object
            @return: a valid session to a remote machine, or None if no remote session was needed
        """
        session = None

        # see if we need to create a remote connection
        if server is not None and server != "localhost":
            username = config.get("remote_user")
            password = config.get("remote_password")
            domain = config.get("remote_domain")
            flags = win32evtlog.EvtRpcLoginAuthDefault

            # login object is a tuple
            login = (server, username, domain, password, flags)
            self._logger.log(
                scalyr_logging.DEBUG_LEVEL_1,
                "Performing remote login: server - %s, user - %s, domain - %s"
                % (server, username, domain),
            )

            session = None
            session = win32evtlog.EvtOpenSession(login, win32evtlog.EvtRpcLogin, 0, 0)

            if session is None:
                # 0 means to call GetLastError for the error code
                error_message = win32api.FormatMessage(0)
                self._logger.warn(
                    "Error connecting to remote server %s, as %s - %s"
                    % (server, username, error_message)
                )
                raise Exception(
                    "Error connecting to remote server %s, as %s - %s"
                    % (server, username, error_message)
                )

        return session 
Example #17
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def Connect(self):
        """
        This function tries to connect to the named pipe from AlternateMceIrService.  If it can't connect, it will periodically
        retry until the plugin is stopped or the connection is made.
        """
        self.connecting = True
        #eg.PrintNotice("MCE_Vista: Connect started")
        while self.file is None and self.keepRunning:
            self.SetReceiving(False)
            try:
                self.file = win32file.CreateFile(r'\\.\pipe\MceIr',win32file.GENERIC_READ
                                        |win32file.GENERIC_WRITE,0,None,
                                        win32file.OPEN_EXISTING,win32file.FILE_ATTRIBUTE_NORMAL
                                        |win32file.FILE_FLAG_OVERLAPPED,None)
                if self.sentMessageOnce:
                    eg.PrintNotice("MCE_Vista: Connected to MceIr pipe, started handling IR events")
                    self.plugin.TriggerEvent("Connected")
                    self.sentMessageOnce = False
            except:
                if not self.sentMessageOnce:
                    eg.PrintNotice("MCE_Vista: MceIr pipe is not available, app doesn't seem to be running")
                    eg.PrintNotice("    Will continue to try to connect to MceIr")
                    eg.PrintNotice("    Message = %s"%win32api.FormatMessage(win32api.GetLastError()))
                    self.plugin.TriggerEvent("Disconnected")
                    self.sentMessageOnce = True

                #if self.service and IsServiceStopped(self.service):
                #    eg.PrintNotice("MCE_Vista: MceIr service is stopped, trying to start it...")
                #    StartService(self.service)

                time.sleep(1)
        self.connecting = False
        return 
Example #18
Source File: win32util.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def __init__(self, WinError, FormatMessage, errorTab):
        self.winError = WinError
        self.formatMessage = FormatMessage
        self.errorTab = errorTab 
Example #19
Source File: test_strerror.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_fromEnvironment(self):
        """
        L{_ErrorFormatter.fromEnvironment} should create an L{_ErrorFormatter}
        instance with attributes populated from available modules.
        """
        formatter = _ErrorFormatter.fromEnvironment()

        if formatter.winError is not None:
            from ctypes import WinError
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                WinError(self.probeErrorCode).strerror)
            formatter.winError = None

        if formatter.formatMessage is not None:
            from win32api import FormatMessage
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                FormatMessage(self.probeErrorCode))
            formatter.formatMessage = None

        if formatter.errorTab is not None:
            from socket import errorTab
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                errorTab[self.probeErrorCode]) 
Example #20
Source File: win32util.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def __init__(self, WinError, FormatMessage, errorTab):
        self.winError = WinError
        self.formatMessage = FormatMessage
        self.errorTab = errorTab 
Example #21
Source File: test_exceptions.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testMessageIndex(self):
        exc = self._getException()
        expected = win32api.FormatMessage(winerror.STG_E_INVALIDFLAG).rstrip()
        self._testExceptionIndex(exc, 1, expected) 
Example #22
Source File: redirector.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def io_callback(ecb, url, cbIO, errcode):
    # Get the status of our ExecURL
    httpstatus, substatus, win32 = ecb.GetExecURLStatus()
    print "ExecURL of %r finished with http status %d.%d, win32 status %d (%s)" % (
           url, httpstatus, substatus, win32, win32api.FormatMessage(win32).strip())
    # nothing more to do!
    ecb.DoneWithSession()

# The ISAPI extension - handles all requests in the site. 
Example #23
Source File: test_bits.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _print_error(self, err):
        ctx, hresult = err.GetError()
        try:
            hresult_msg = win32api.FormatMessage(hresult)
        except win32api.error:
            hresult_msg  = ""
        print "Context=0x%x, hresult=0x%x (%s)" % (ctx, hresult, hresult_msg)
        print err.GetErrorDescription() 
Example #24
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def WaitForServiceStatus(serviceName, status, waitSecs, machine=None):
    """Waits for the service to return the specified status.  You
    should have already requested the service to enter that state"""
    for i in range(waitSecs*4):
        now_status = QueryServiceStatus(serviceName, machine)[1]
        if now_status == status:
            break
        win32api.Sleep(250)
    else:
        raise pywintypes.error(winerror.ERROR_SERVICE_REQUEST_TIMEOUT, "QueryServiceStatus", win32api.FormatMessage(winerror.ERROR_SERVICE_REQUEST_TIMEOUT)[:-2]) 
Example #25
Source File: test_win32api.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_FromString(self):
        msg = "Hello %1, how are you %2?"
        inserts = ["Mark", "today"]
        result = win32api.FormatMessage(win32con.FORMAT_MESSAGE_FROM_STRING,
                               msg, # source
                               0, # ID
                               0, # LangID
                               inserts)
        self.assertEqual(result, "Hello Mark, how are you today?") 
Example #26
Source File: test_exceptions.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testUnpack(self):
        try:
            win32api.CloseHandle(1)
            self.fail("expected exception!")
        except win32api.error, exc:
            self.failUnlessEqual(exc.winerror, winerror.ERROR_INVALID_HANDLE)
            self.failUnlessEqual(exc.funcname, "CloseHandle")
            expected_msg = win32api.FormatMessage(winerror.ERROR_INVALID_HANDLE).rstrip()
            self.failUnlessEqual(exc.strerror, expected_msg) 
Example #27
Source File: test_exceptions.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testAsStr(self):
        exc = self._getInvalidHandleException()
        err_msg = win32api.FormatMessage(winerror.ERROR_INVALID_HANDLE).rstrip()
        # early on the result actually *was* a tuple - it must always look like one
        err_tuple = (winerror.ERROR_INVALID_HANDLE, 'CloseHandle', err_msg)
        self.failUnlessEqual(str(exc), str(err_tuple)) 
Example #28
Source File: test_exceptions.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testAsTuple(self):
        exc = self._getInvalidHandleException()
        err_msg = win32api.FormatMessage(winerror.ERROR_INVALID_HANDLE).rstrip()
        # early on the result actually *was* a tuple - it must be able to be one
        err_tuple = (winerror.ERROR_INVALID_HANDLE, 'CloseHandle', err_msg)
        if sys.version_info < (3,):
            self.failUnlessEqual(tuple(exc), err_tuple)
        else:
            self.failUnlessEqual(exc.args, err_tuple) 
Example #29
Source File: test_exceptions.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testAttributes(self):
        exc = self._getInvalidHandleException()
        err_msg = win32api.FormatMessage(winerror.ERROR_INVALID_HANDLE).rstrip()
        self.failUnlessEqual(exc.winerror, winerror.ERROR_INVALID_HANDLE)
        self.failUnlessEqual(exc.strerror, err_msg)
        self.failUnlessEqual(exc.funcname, 'CloseHandle')

    # some tests for 'insane' args. 
Example #30
Source File: win32.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def __init__(self, WinError, FormatMessage, errorTab):
        self.winError = WinError
        self.formatMessage = FormatMessage
        self.errorTab = errorTab