Jump to content

WMI error handling.


Recommended Posts

Good day,

I'm creating a simple WMI function to scan networks for uptimes on our terminal servers and some more, But I have a problem.

The WMI scripts words as it should be, however, when you input a wrong computer name, it just ends the entire programm and doesn't give me back what I want to get back: "Computer doesn't excist error message".

$strComputer="localhost"
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
    For $objItem In $colItems
        $SystemUptime = ($objItem.SystemUpTime / 60)
            Dim $SystemUptimeDay
            Dim $SystemUptimeHour
            Dim $SystemUptimeMin
            Dim $SystemUptimeSec
            $SystemUptimeDay = Int($objItem.SystemUpTime / 86400)
            $SystemUptimeHour = Int($objItem.SystemUpTime / 3600) - ($SystemUptimeDay * 24)
            $SystemUptimeMin = Int($objItem.SystemUpTime / 60) - ($SystemUptimeHour * 60) - ($SystemUptimeDay * 24 * 60)
            $SystemUptimeSec = Int($objItem.SystemUpTime) - ($SystemUptimeMin * 60) - ($SystemUptimeHour * 60 * 60) - ($SystemUptimeDay * 24 * 60 * 60)
            $Output=($strComputer & "     " & $SystemUptimeDay & "d " & " " & $SystemUptimeHour & ":" & $SystemUptimeMin & "," & $SystemUptimeSec)
         MsgBox(1, "", $Output)
    Next


Endif

Above is the working code, it gives you the uptime in a popup box of the localhost, however, change the strcomputer to something unresolvable and the script just dies.

It give me the following in Scite console:

C:\Users\Blabla\Desktop\test.au3 (9) : ==> Variable must be of type "Object".:

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

$colItems = $objWMIService^ ERROR

->19:26:17 AutoIT3.exe ended.rc:1

What I want is it giving me back a message saying its unresolvable.

Can somebody give me some help witht his?

Thank you.

Link to comment
Share on other sites

You have to add an error handling!

Try this:

$strComputer="localhost"
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""

$oErrors = ObjEvent("AutoIt.Error", "Error_Handle")

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _
    $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
    For $objItem In $colItems
    $SystemUptime = ($objItem.SystemUpTime / 60)
    Dim $SystemUptimeDay
    Dim $SystemUptimeHour
    Dim $SystemUptimeMin
    Dim $SystemUptimeSec
    $SystemUptimeDay = Int($objItem.SystemUpTime / 86400)
    $SystemUptimeHour = Int($objItem.SystemUpTime / 3600) - ($SystemUptimeDay * 24)
    $SystemUptimeMin = Int($objItem.SystemUpTime / 60) - ($SystemUptimeHour * 60) - ($SystemUptimeDay * 24 * 60)
    $SystemUptimeSec = Int($objItem.SystemUpTime) - ($SystemUptimeMin * 60) - ($SystemUptimeHour * 60 * 60) - ($SystemUptimeDay * 24 * 60 * 60)
    $Output=($strComputer & "   " & $SystemUptimeDay & "d " & " " & $SystemUptimeHour & ":" & $SystemUptimeMin & "," & $SystemUptimeSec)
    MsgBox(1, "", $Output)
    Next


Endif

Func Error_Handle()
    Msgbox(0, "Debug Information", "An error has occured!" & @CRLF & @CRLF & _
             "err.description is: " & @TAB & $oErrors.description   & @CRLF & _
             "err.windescription:"  & @TAB & $oErrors.windescription & @CRLF & _
             "err.number is: "  & @TAB & Hex($oErrors.number,8) & @CRLF & _
             "err.lastdllerror is: " & @TAB & $oErrors.lastdllerror & @CRLF & _
             "err.scriptline is: "  & @TAB & $oErrors.scriptline    & @CRLF & _
             "err.source is: "  & @TAB & $oErrors.source    & @CRLF & _
             "err.helpfile is: "    & @TAB & $oErrors.helpfile  & @CRLF & _
             "err.helpcontext is: " & @TAB & $oErrors.helpcontext   & @CRLF & @CRLF & @CRLF)
    Return SetError($oErrors.number)

#comments-start
Error Codes:
    Automation  Automation  Error Description
    Error       Error
    in Decimal  in Hex
    -2147467255 0x00084009  Unable to initialize class cache.
    -2147467254 0x0008400A  Unable to initialize RPC services.
    -2147483647 0x80000001  Not implemented.
    -2147483646 0x80000002  Ran out of memory.
    -2147483645 0x80000003  One or more arguments are invalid.
    -2147483644 0x80000004  No such interface supported.
    -2147483643 0x80000005  Invalid pointer.
    -2147483642 0x80000006  Invalid handle.
    -2147483641 0x80000007  Operation aborted.
    -2147483640 0x80000008  Unspecified error.
    -2147483639 0x80000009  General access denied error.
    -2147483638 0x8000000A  The data necessary to complete this operation not yet available.
    -2147467263 0x80004001  Not implemented.
    -2147467262 0x80004002  No such interface supported.
    -2147467261 0x80004003  Invalid pointer.
    -2147467260 0x80004004  Operation aborted.
    -2147467259 0x80004005  Unspecified error.
    -2147467258 0x80004006  Thread local storage failure.
    -2147467257 0x80004007  Get shared memory allocator failure.
    -2147467256 0x80004008  Get memory allocator failure.
    -2147467253 0x8000400B  Cannot set thread local storage channel control.
    -2147467252 0x8000400C  Could not allocate thread local storage channel control.
    -2147467251 0x8000400D  The user supplied memory allocator is unacceptable.
    -2147467250 0x8000400E  The OLE service mutex already exists.
    -2147467249 0x8000400F  The OLE service file mapping already exists.
    -2147467248 0x80004010  Unable to map view of file for OLE service.
    -2147467247 0x80004011  Failure attempting to launch OLE service.
    -2147467246 0x80004012  There was an attempt to call CoInitialize a second time while single threaded.
    -2147467245 0x80004013  A Remote activation was necessary but was not allowed.
    -2147467244 0x80004014  A Remote activation was necessary but the server name provided was invalid.
    -2147467243 0x80004015  The class is configured to run as a security id different from the caller.
    -2147467242 0x80004016  Use of Ole1 services requiring DDE windows is disabled.
    -2147467241 0x80004017  A RunAs specification must be A RunAs specification must be <domain name>\<user name> or simply <user name>.
    -2147467240 0x80004018  The server process could not be started. The pathname may be incorrect.
    -2147467239 0x80004019  The server process could not be started as the configured identity. The pathname may be incorrect or unavailable.
    -2147467238 0x8000401A  The server process could not be started because the configured identity is incorrect. Check the username and password.
    -2147467237 0x8000401B  The client is not allowed to launch this server.
    -2147467236 0x8000401C  The service providing this server could not be started.
    -2147467235 0x8000401D  This computer was unable to communicate with the computer providing the server.
    -2147467234 0x8000401E  The server did not respond after being launched.
    -2147467233 0x8000401F  The registration information for this server is inconsistent or incomplete.
    -2147467232 0x80004020  The registration information for this interface is inconsistent or incomplete.
    -2147467231 0x80004021  The operation attempted is not supported.
    -2147418113 0x8000FFFF  Catastrophic failure.
    -2147418111 0x80010001  Call was rejected by callee.
    -2147418110 0x80010002  Call was canceled by the message filter.
    -2147418109 0x80010003  The caller is dispatching an intertask SendMessage call and cannot call out via PostMessage.
    -2147418108 0x80010004  The caller is dispatching an asynchronous call and cannot make an outgoing call on behalf of this call.
    -2147418107 0x80010005  It is illegal to call out while inside message filter.
    -2147418106 0x80010006  The connection terminated or is in a bogus state and cannot be used any more. Other connections are still valid.
    -2147418105 0x80010007  The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call may have executed.
    -2147418104 0x80010008  The caller (client) disappeared while the callee (server) was processing a call.
    -2147418103 0x80010009  The data packet with the marshalled parameter data is incorrect.
    -2147418102 0x8001000A  The call was not transmitted properly; the message queue was full and was not emptied after yielding.
    -2147418101 0x8001000B  The client (caller) cannot marshal the parameter data - low memory, etc.
    -2147418100 0x8001000C  The client (caller) cannot unmarshal the return data - low memory, etc.
    -2147418099 0x8001000D  The server (callee) cannot marshal the return data - low memory, etc.
    -2147418098 0x8001000E  The server (callee) cannot unmarshal the parameter data - low memory, etc.
    -2147418097 0x8001000F  Received data is invalid; could be server or client data.
    -2147418096 0x80010010  A particular parameter is invalid and cannot be (un)marshalled.
    -2147418095 0x80010011  There is no second outgoing call on same channel in DDE conversation.
    -2147418094 0x80010012  The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call did not execute.
    -2147417856 0x80010100  System call failed.
    -2147417855 0x80010101  Could not allocate some required resource (memory, events, ...)
    -2147417854 0x80010102  Attempted to make calls on more than one thread in single threaded mode.
    -2147417853 0x80010103  The requested interface is not registered on the server object.
    -2147417852 0x80010104  RPC could not call the server or could not return the results of calling the server.
    -2147417851 0x80010105  The server threw an exception.
    -2147417850 0x80010106  Cannot change thread mode after it is set.
    -2147417849 0x80010107  The method called does not exist on the server.
    -2147417848 0x80010108  The object invoked has disconnected from its clients.
    -2147417847 0x80010109  The object invoked chose not to process the call now. Try again later.
    -2147417846 0x8001010A  The message filter indicated that the application is busy.
    -2147417845 0x8001010B  The message filter rejected the call.
    -2147417844 0x8001010C  A call control interfaces was called with invalid data.
    -2147417843 0x8001010D  An outgoing call cannot be made since the application is dispatching an input-synchronous call.
    -2147417842 0x8001010E  The application called an interface that was marshalled for a different thread.
    -2147417841 0x8001010F  CoInitialize has not been called on the current thread.
    -2147417840 0x80010110  The version of OLE on the client and server machines does not match.
    -2147417839 0x80010111  OLE received a packet with an invalid header.
    -2147417838 0x80010112  OLE received a packet with an invalid extension.
    -2147417837 0x80010113  The requested object or interface does not exist.
    -2147417836 0x80010114  The requested object does not exist.
    -2147417835 0x80010115  OLE has sent a request and is waiting for a reply.
    -2147417834 0x80010116  OLE is waiting before retrying a request.
    -2147417833 0x80010117  Call context cannot be accessed after call completed.
    -2147417832 0x80010118  Impersonate on unsecured calls is not supported.
    -2147417831 0x80010119  Security must be initialized before any interfaces are marshalled or unmarshalled. It cannot be changed once initialized.
    -2147417830 0x8001011A  No security packages are installed on this machine or the user is not logged on or there are no compatible security packages between the client and server.
    -2147417829 0x8001011B  Access is denied.
    -2147417828 0x8001011C  Remote calls are not allowed for this process.
    -2147417827 0x8001011D  The marshalled interface data packet (oBJREF) has an invalid or unknown format.
    -2147352577 0x8001FFFF  An internal error occurred.
    -2147352575 0x80020001  Unknown interface.
    -2147352573 0x80020003  Member not found.
    -2147352572 0x80020004  Parameter not found.
    -2147352571 0x80020005  Type mismatch.
    -2147352570 0x80020006  Unknown name.
    -2147352569 0x80020007  No named arguments.
    -2147352568 0x80020008  Bad variable type.
    -2147352567 0x80020009  Exception occurred.
    -2147352566 0x8002000A  Out of present range.
    -2147352565 0x8002000B  Invalid index.
    -2147352564 0x8002000C  Unknown language.
    -2147352563 0x8002000D  Memory is locked.
    -2147352562 0x8002000E  Invalid number of parameters.
    -2147352561 0x8002000F  Parameter not optional.
    -2147352560 0x80020010  Invalid callee.
    -2147352559 0x80020011  Does not support a collection.
    -2147319786 0x80028016  Buffer too small.
    -2147319784 0x80028018  Old format or invalid type library.
    -2147319783 0x80028019  Old format or invalid type library.
    -2147319780 0x8002801C  Error accessing the OLE registry.
    -2147319779 0x8002801D  Library not registered.
    -2147319769 0x80028027  Bound to unknown type.
    -2147319768 0x80028028  Qualified name disallowed.
    -2147319767 0x80028029  Invalid forward reference, or reference to uncompiled type.
    -2147319766 0x8002802A  Type mismatch.
    -2147319765 0x8002802B  Element not found.
    -2147319764 0x8002802C  Ambiguous name.
    -2147319763 0x8002802D  Name already exists in the library.
    -2147319762 0x8002802E  Unknown LCID.
    -2147319761 0x8002802F  Function not defined in specified DLL.
    -2147317571 0x800288BD  Wrong module kind for the operation.
    -2147317563 0x800288C5  Size may not exceed 64K.
    -2147317562 0x800288C6  Duplicate ID in inheritance hierarchy.
    -2147317553 0x800288CF  Incorrect inheritance depth in standard OLE hmember.
    -2147316576 0x80028CA0  Type mismatch.
    -2147316575 0x80028CA1  Invalid number of arguments.
    -2147316574 0x80028CA2  I/O Error.
    -2147316573 0x80028CA3  Error creating unique tmp file.
    -2147312566 0x80029C4A  Error loading type library/DLL.
    -2147312509 0x80029C83  Inconsistent property functions.
    -2147312508 0x80029C84  Circular dependency between types/modules.
    -2147287039 0x80030001  Unable to perform requested operation.
    -2147287038 0x80030002  %1 could not be found.
    -2147287037 0x80030003  The path %1 could not be found.
    -2147287036 0x80030004  There are insufficient resources to open another file.
    -2147287035 0x80030005  Access Denied.
    -2147287034 0x80030006  Attempted an operation on an invalid object.
    -2147287032 0x80030008  There is insufficient memory available to complete operation.
    -2147287031 0x80030009  Invalid pointer error.
    -2147287022 0x80030012  There are no more entries to return.
    -2147287021 0x80030013  Disk is write-protected.
    -2147287015 0x80030019  An error occurred during a seek operation.
    -2147287011 0x8003001D  A disk error occurred during a write operation.
    -2147287010 0x8003001E  A disk error occurred during a read operation.
    -2147287008 0x80030020  A share violation has occurred.
    -2147287007 0x80030021  A lock violation has occurred.
    -2147286960 0x80030050  %1 already exists.
    -2147286953 0x80030057  Invalid parameter error.
    -2147286928 0x80030070  There is insufficient disk space to complete operation.
    -2147286800 0x800300F0  Illegal write of non-simple property to simple property set.
    -2147286790 0x800300FA  An API call exited abnormally.
    -2147286789 0x800300FB  The file %1 is not a valid compound file.
    -2147286788 0x800300FC  The name %1 is not valid.
    -2147286787 0x800300FD  An unexpected error occurred.
    -2147286786 0x800300FE  That function is not implemented.
    -2147286785 0x800300FF  Invalid flag error.
    -2147286784 0x80030100  Attempted to use an object that is busy.
    -2147286783 0x80030101  The storage has been changed since the last commit.
    -2147286782 0x80030102  Attempted to use an object that has ceased to exist.
    -2147286781 0x80030103  Can't save.
    -2147286780 0x80030104  The compound file %1 was produced with an incompatible version of storage.
    -2147286779 0x80030105  The compound file %1 was produced with a newer version of storage.
    -2147286778 0x80030106  Share.exe or equivalent is required for operation.
    -2147286777 0x80030107  Illegal operation called on non-file based storage.
    -2147286776 0x80030108  Illegal operation called on object with extant marshallings.
    -2147286775 0x80030109  The docfile has been corrupted.
    -2147286768 0x80030110  OLE32.DLL has been loaded at the wrong address.
    -2147286527 0x80030201  The file download was aborted abnormally. The file is incomplete.
    -2147286526 0x80030202  The file download has been terminated.
    -2147221504 0x80040000  Invalid OLEVERB structure.
    -2147221503 0x80040001  Invalid advise flags.
    -2147221502 0x80040002  Can't enumerate anymore, because the associated data is missing.
    -2147221501 0x80040003  This implementation doesn't take advises.
    -2147221500 0x80040004  There is no connection for this connection ID.
    -2147221499 0x80040005  Need to run the object to perform this operation.
    -2147221498 0x80040006  There is no cache to operate on.
    -2147221497 0x80040007  Uninitialized object.
    -2147221496 0x80040008  Linked object's source class has changed.
    -2147221495 0x80040009  Not able to get the moniker of the object.
    -2147221494 0x8004000A  Not able to bind to the source.
    -2147221493 0x8004000B  Object is static; operation not allowed.
    -2147221492 0x8004000C  User cancelled out of save dialog.
    -2147221491 0x8004000D  Invalid rectangle.
    -2147221490 0x8004000E  compobj.dll is too old for the ole2.dll initialized.
    -2147221489 0x8004000F  Invalid window handle.
    -2147221488 0x80040010  Object is not in any of the inplace active states.
    -2147221487 0x80040011  Not able to convert object.
    -2147221486 0x80040012  Not able to perform the operation because object is not given storage yet.
    -2147221404 0x80040064  Invalid FORMATETC structure.
    -2147221403 0x80040065  Invalid DVTARGETDEVICE structure.
    -2147221402 0x80040066  Invalid STDGMEDIUM structure.
    -2147221401 0x80040067  Invalid STATDATA structure.
    -2147221400 0x80040068  Invalid lindex.
    -2147221399 0x80040069  Invalid tymed.
    -2147221398 0x8004006A  Invalid clipboard format.
    -2147221397 0x8004006B  Invalid aspect(s).
    -2147221396 0x8004006C  tdSize parameter of the DVTARGETDEVICE structure is invalid.
    -2147221395 0x8004006D  Object doesn't support IViewObject interface.
    -2147221248 0x80040100  Trying to revoke a drop target that has not been registered.
    -2147221247 0x80040101  This window has already been registered as a drop target.
    -2147221246 0x80040102  Invalid window handle.
    -2147221232 0x80040110  Class does not support aggregation (or class object is remote).
    -2147221231 0x80040111  ClassFactory cannot supply requested class.
    -2147221184 0x80040140  Error drawing view.
    -2147221168 0x80040150  Could not read key from registry.
    -2147221167 0x80040151  Could not write key to registry.
    -2147221166 0x80040152  Could not find the key in the registry.
    -2147221165 0x80040153  Invalid value for registry.
    -2147221164 0x80040154  Class not registered.
    -2147221163 0x80040155  Interface not registered.
    -2147221136 0x80040170  Cache not updated.
    -2147221120 0x80040180  No verbs for OLE object.
    -2147221119 0x80040181  Invalid verb for OLE object.
    -2147221088 0x800401A0  Undo is not available.
    -2147221087 0x800401A1  Space for tools is not available.
    -2147221056 0x800401C0  OLESTREAM Get method failed.
    -2147221055 0x800401C1  OLESTREAM Put method failed.
    -2147221054 0x800401C2  Contents of the OLESTREAM not in correct format.
    -2147221053 0x800401C3  There was an error in a Windows GDI call while converting the bitmap to a DIB.
    -2147221052 0x800401C4  Contents of the IStorage not in correct format.
    -2147221051 0x800401C5  Contents of IStorage is missing one of the standard streams.
    -2147221050 0x800401C6  There was an error in a Windows GDI call while converting the DIB to a bitmap.
    -2147221040 0x800401D0  OpenClipboard Failed.
    -2147221039 0x800401D1  EmptyClipboard Failed.
    -2147221038 0x800401D2  SetClipboard Failed.
    -2147221037 0x800401D3  Data on clipboard is invalid.
    -2147221036 0x800401D4  CloseClipboard Failed.
    -2147221024 0x800401E0  Moniker needs to be connected manually.
    -2147221023 0x800401E1  Operation exceeded deadline.
    -2147221022 0x800401E2  Moniker needs to be generic.
    -2147221021 0x800401E3  Operation unavailable.
    -2147221020 0x800401E4  Invalid syntax.
    -2147221019 0x800401E5  No object for moniker.
    -2147221018 0x800401E6  Bad extension for file.
    -2147221017 0x800401E7  Intermediate operation failed.
    -2147221016 0x800401E8  Moniker is not bindable.
    -2147221015 0x800401E9  Moniker is not bound.
    -2147221014 0x800401EA  Moniker cannot open file.
    -2147221013 0x800401EB  User input required for operation to succeed.
    -2147221012 0x800401EC  Moniker class has no inverse.
    -2147221011 0x800401ED  Moniker does not refer to storage.
    -2147221010 0x800401EE  No common prefix.
    -2147221009 0x800401EF  Moniker could not be enumerated.
    -2147221008 0x800401F0  CoInitialize has not been called.
    -2147221007 0x800401F1  CoInitialize has already been called.
    -2147221006 0x800401F2  Class of object cannot be determined.
    -2147221005 0x800401F3  Invalid class string.
    -2147221004 0x800401F4  Invalid interface string.
    -2147221003 0x800401F5  Application not found.
    -2147221002 0x800401F6  Application cannot be run more than once.
    -2147221001 0x800401F7  Some error in application program.
    -2147221000 0x800401F8  DLL for class not found.
    -2147220999 0x800401F9  Error in the DLL.
    -2147220998 0x800401FA  Wrong OS or OS version for application.
    -2147220997 0x800401FB  Object is not registered.
    -2147220996 0x800401FC  Object is already registered.
    -2147220995 0x800401FD  Object is not connected to server.
    -2147220994 0x800401FE  Application was launched but it didn't register a class factory.
    -2147220993 0x800401FF  Object has been released.
                0x80041001  Failed
                0x80041002  Not Found
                0x80041003  Access Denied (user rights)
                0x80041004  Provider Failure
                0x80041005  Type Mismatch
                0x80041006  Out Of Memory
                0x80041007  Invalid Context
                0x80041008  Invalid Parameter
                0x80041009  Not Available
                0x8004100A  Critical Error
                0x8004100B  Invalid Stream
                0x8004100C  Not Supported
                0x8004100D  Invalid Superclass
                0x8004100E  Invalid Namespace
                0x8004100F  Invalid Object
                0x80041010  Invalid Class
                0x80041011  Provider Not Found
                0x80041012  Invalid Provider Registration
                0x80041013  Provider Load Failure
                0x80041014  Initialization Failure
                0x80041015  Transport Failure
                0x80041016  Invalid Operation
                0x80041017  Invalid Query
                0x80041018  Invalid Query Type
                0x80041019  Already Exists
                0x8004101A  Override Not Allowed
                0x8004101B  Propagated Qualifier
                0x8004101C  Propagated Property
                0x8004101D  Unexpected
                0x8004101E  Illegal Operation
                0x8004101F  Cannot Be Key
                0x80041020  Incomplete Class
                0x80041021  Invalid Syntax
                0x80041022  Nondecorated Object
                0x80041023  Read Only
                0x80041024  Provider Not Capable
                0x80041025  Class Has Children
                0x80041026  Class Has Instances
                0x80041027  Query Not Implemented
                0x80041028  Illegal Null
                0x80041029  Invalid Qualifier Type
                0x8004102A  Invalid Property Type
                0x8004102B  Value Out Of Range
                0x8004102C  Cannot Be Singleton
                0x8004102D  Invalid Cim Type
                0x8004102E  Invalid Method
                0x8004102F  Invalid Method Parameters
                0x80041030  System Property
                0x80041031  Invalid Property
                0x80041032  Call Cancelled
                0x80041033  Shutting Down
                0x80041034  Propagated Method
                0x80041035  Unsupported Parameter
                0x80041036  Missing Parameter Id
                0x80041037  Invalid Parameter Id
                0x80041038  Nonconsecutive Parameter Ids
                0x80041039  Parameter Id On Retval
                0x8004103A  Invalid Object Path
                0x8004103B  Out Of Disk Space
                0x8004103C  Buffer Too Small
                0x8004103D  Unsupported Put Extension
                0x8004103E  Unknown Object Type
                0x8004103F  Unknown Packet Type
                0x80041040  Marshal Version Mismatch
                0x80041041  Marshal Invalid Signature
                0x80041042  Invalid Qualifier
                0x80041043  Invalid Duplicate Parameter
                0x80041044  Too Much Data
                0x80041045  Server Too Busy
                0x80041046  Invalid Flavor
                0x80041047  Circular Reference
                0x80041048  Unsupported Class Update
                0x80041049  Cannot Change Key Inheritance
                0x80041050  Cannot Change Index Inheritance
                0x80041051  Too Many Properties
                0x80041052  Update Type Mismatch
                0x80041053  Update Override Not Allowed
                0x80041054  Update Propagated Method
                0x80041055  Method Not Implemented
                0x80041056  Method Disabled
                0x80041064  User credentials cannot be used for local connections
                0x8004106C  WMI is taking up too much memory
                0x80042001  Wbemess E Registration Too Broad
                0x80042002  Wbemess E Registration Too Precise
    -2147024891 0x80070005  General access denied error (incorrect login).
    -2147024890 0x80070006  Invalid handle.
    -2147942413 0x8007000D  The Data is invalid.
    -2147024882 0x8007000E  Ran out of memory.
    -2147024809 0x80070057  One or more arguments are invalid.
                0x800706BA  The RPC server is unavailable
    -2146959359 0x80080001  Attempt to create a class object failed.
    -2146959358 0x80080002  OLE service could not bind object.
    -2146959357 0x80080003  RPC communication failed with OLE service.
    -2146959356 0x80080004  Bad path to object.
    -2146959355 0x80080005  Internal execution failure in the WMI Service.
    -2146959354 0x80080006  OLE service could not communicate with the object server.
    -2146959353 0x80080007  Moniker path could not be normalized.
    -2146959352 0x80080008  Object server is stopping when OLE service contacts it.
    -2146959351 0x80080009  An invalid root block pointer was specified.
    -2146959344 0x80080010  An allocation chain contained an invalid link pointer.
    -2146959343 0x80080011  The requested allocation size was too large.
    -2146893823 0x80090001  Bad UID.
    -2146893822 0x80090002  Bad Hash.
    -2146893821 0x80090003  Bad Key.
    -2146893820 0x80090004  Bad Length.
    -2146893819 0x80090005  Bad Data.
    -2146893818 0x80090006  Invalid Signature.
    -2146893817 0x80090007  Bad Version of provider.
    -2146893816 0x80090008  Invalid algorithm specified.
    -2146893815 0x80090009  Invalid flags specified.
    -2146893814 0x8009000A  Invalid type specified.
    -2146893813 0x8009000B  Key not valid for use in specified state.
    -2146893812 0x8009000C  Hash not valid for use in specified state.
    -2146893811 0x8009000D  Key does not exist.
    -2146893810 0x8009000E  Insufficient memory available for the operation.
    -2146893809 0x8009000F  Object already exists.
    -2146893808 0x80090010  Access denied.
    -2146893807 0x80090011  Object was not found.
    -2146893806 0x80090012  Data already encrypted.
    -2146893805 0x80090013  Invalid provider specified.
    -2146893804 0x80090014  Invalid provider type specified.
    -2146893803 0x80090015  Provider's public key is invalid.
    -2146893802 0x80090016  Keyset does not exist.
    -2146893801 0x80090017  Provider type not defined.
    -2146893800 0x80090018  Provider type as registered is invalid.
    -2146893799 0x80090019  The keyset is not defined.
    -2146893798 0x8009001A  Keyset as registered is invalid.
    -2146893797 0x8009001B  Provider type does not match registered value.
    -2146893796 0x8009001C  The digital signature file is corrupt.
    -2146893795 0x8009001D  Provider DLL failed to initialize correctly.
    -2146893794 0x8009001E  Provider DLL could not be found.
    -2146893793 0x8009001F  The Keyset parameter is invalid.
    -2146893792 0x80090020  An internal error occurred.
    -2146893791 0x80090021  A base error occurred.
    -2146762751 0x800B0001  The specified trust provider is not known on this system.
    -2146762750 0x800B0002  The trust verification action specified is not supported by the specified trust provider.
    -2146762749 0x800B0003  The form specified for the subject is not one supported or known by the specified trust provider.
    -2146762748 0x800B0004  The subject is not trusted for the specified action.
    -2146762747 0x800B0005  Error due to problem in ASN.1 encoding process.
    -2146762746 0x800B0006  Error due to problem in ASN.1 decoding process.
    -2146762745 0x800B0007  Reading / writing Extensions where Attributes are appropriate, and visa versa.
    -2146762744 0x800B0008  Unspecified cryptographic failure.
    -2146762743 0x800B0009  The size of the data could not be determined.
    -2146762742 0x800B000A  The size of the indefinite-sized data could not be determined.
    -2146762741 0x800B000B  This object does not read and write self-sizing data.
    -2146762496 0x800B0100  No signature was present in the subject.
    -2146762495 0x800B0101  A required certificate is not within its validity period.
    -2146762494 0x800B0102  The validity periods of the certification chain do not nest correctly.
    -2146762493 0x800B0103  A certificate that can only be used as an end-entity is being used as a CA or visa versa.
    -2146762492 0x800B0104  A path length constraint in the certification chain has been violated.
    -2146762491 0x800B0105  An extension of unknown type that is labeled 'critical' is present in a certificate.
    -2146762490 0x800B0106  A certificate is being used for a purpose other than that for which it is permitted.
    -2146762489 0x800B0107  A parent of a given certificate in fact did not issue that child certificate.
    -2146762488 0x800B0108  A certificate is missing or has an empty value for an important field, such as a subject or issuer name.
    -2146762487 0x800B0109  A certification chain processed correctly, but terminated in a root certificate which isn't trusted by the trust provider.
    -2146762486 0x800B010A  A chain of certs didn't chain as they should in a certain application of chaining.

#comments-end

EndFunc

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks, that seems to work stand alone like a charm!

But not when turned into a function, and thats what I need:

;_FuncUptime.au3:

Global $oErrors = ObjEvent("AutoIt.Error", "Error_Handle")
Func _FuncUptime($strComputer)

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""



$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _
    $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
    For $objItem In $colItems
    $SystemUptime = ($objItem.SystemUpTime / 60)
    Dim $SystemUptimeDay
    Dim $SystemUptimeHour
    Dim $SystemUptimeMin
    Dim $SystemUptimeSec
    $SystemUptimeDay = Int($objItem.SystemUpTime / 86400)
    $SystemUptimeHour = Int($objItem.SystemUpTime / 3600) - ($SystemUptimeDay * 24)
    $SystemUptimeMin = Int($objItem.SystemUpTime / 60) - ($SystemUptimeHour * 60) - ($SystemUptimeDay * 24 * 60)
    $SystemUptimeSec = Int($objItem.SystemUpTime) - ($SystemUptimeMin * 60) - ($SystemUptimeHour * 60 * 60) - ($SystemUptimeDay * 24 * 60 * 60)
    $Output=($strComputer & "   " & $SystemUptimeDay & "d " & " " & $SystemUptimeHour & ":" & $SystemUptimeMin & "," & $SystemUptimeSec)
    MsgBox(1, "", $Output)
    Next
Return $Output

Endif
EndFunc

Func Error_Handle()
    ;$oErrors = ObjEvent("AutoIt.Error", "Error_Handle")
    $Output=("err.windescription:"  & $oErrors.windescription )
    Return SetError($oErrors.number)

EndFunc

#include "Func_Uptime.au3"

_FuncUptime("testblabla")
_FuncUptime("localhost")

Now you get some weird error, only when it should fail, or while doing 2 at a time, while it functions correct when usng localhost:

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

$colItems = ^ ERROR

Got any ideas?

Link to comment
Share on other sites

It jumps to the error function but crashes with a script error! I don't know why!

C:\Test\test01.au3 (17) : ==> Missing right bracket ')' in expression.:
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", 0x30)
$colItems = ^ ERROR

But you can ping system before you try to get information from that system:

Global $oErrors = ObjEvent("AutoIt.Error", "Error_Handle")

MsgBox(0, "Test", _FuncUptime("localhost"))
MsgBox(0, "Test", _FuncUptime("localhost1"))

Func _FuncUptime($strComputer)

    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""

    If Ping($strComputer) Then

        $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $strComputer & "\root\cimv2")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", 0x30)
        If IsObj($colItems) then
            For $objItem In $colItems
                $SystemUptime = ($objItem.SystemUpTime / 60)
                Dim $SystemUptimeDay
                Dim $SystemUptimeHour
                Dim $SystemUptimeMin
                Dim $SystemUptimeSec
                $SystemUptimeDay = Int($objItem.SystemUpTime / 86400)
                $SystemUptimeHour = Int($objItem.SystemUpTime / 3600) - ($SystemUptimeDay * 24)
                $SystemUptimeMin = Int($objItem.SystemUpTime / 60) - ($SystemUptimeHour * 60) - ($SystemUptimeDay * 24 * 60)
                $SystemUptimeSec = Int($objItem.SystemUpTime) - ($SystemUptimeMin * 60) - ($SystemUptimeHour * 60 * 60) - ($SystemUptimeDay * 24 * 60 * 60)
                $Output=($strComputer & " " & $SystemUptimeDay & "d " & " " & $SystemUptimeHour & ":" & $SystemUptimeMin & "," & $SystemUptimeSec)
            Next
        Endif
    Else
        $Output = "Error"
    EndIf
    Return $Output
EndFunc

Func Error_Handle()
    Local $err = $oErrors.number
    If $err = 0 Then $err = -1
    $Output = $err
    Return
EndFunc

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

It jumps to the error function but crashes with a script error! I don't know why!

But you can ping system before you try to get information from that system:

UEZ

Thanks for the help.

Yes, indeed, it crashes, but I can't figure out why that was.

Ping works indeed, but it's not as foolproof as a wmi-connect error check, since ping can still give a correct answer, but wmi can be shut down.

I still wonder why the error checking on WMI doesn't work as should be. Maybe it's a bug or something?

Link to comment
Share on other sites

I had similar problems -> Problem with ObjGet() but ObjEvent("AutoIt.Error", "Error_Handle") fixed my problem in SIC2!

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks, but thats a bit different then my problem.

I think I found out why it doesn't work!

I want the output to be: "computername + error message"

However, the error handler doesn't allow computer names, it just sees a error and nothng more. I think my problem is somewhere in there.

Link to comment
Share on other sites

I managed to create a work arround using an extra WMICheck function:

Func _FuncWMICheck($strComputer)
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$qErrors = ObjEvent("AutoIt.Error", "Error_Handle1")
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
if @error then $WMICheck=2
If IsObj($objWMIService) then
    $WMICheck=1
EndIf
Return $WMICheck
EndFunc

Func Error_Handle1($strComputer)
   $WMICheck=2
    Return $WMICheck
EndFunc

The output is $WMICheck=1 or 2.

If 1 then it's ok, if 2 then its broken.

Then I check this from the gui using:

If GUICtrlRead($ChkUpt) = $GUI_CHECKED Then $WMICheck=_FuncWMICheck($Target)

If GUICtrlRead($ChkUpt) = $GUI_CHECKED And $WMICheck=1 Then _GUICtrlEdit_AppendText($Output1, _FuncUptime($Target)& @CRLF)

If GUICtrlRead($ChkUpt) = $GUI_CHECKED And $WMICheck=2 Then _GUICtrlEdit_AppendText($Output1, $Target & " = WMI ERROR" & @CRLF)

Seems to work like a charm. If ok, then it goes on.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...