Sign in to follow this  
Followers 0
michael

Error: Variable Must Be Of Type "object"

5 posts in this topic

#1 ·  Posted (edited)

I used a portion of a script from Script-o-matic and AutoIt beta version 3.1.1.113 to write a script to return the hard drive model number.

Over 500 of my users have had no problems running the application that utilizes the result, but a couple (literally 2), are getting the following error:

$colItems=$objWMIService.ExecQuery(*SELECT * FROM Win32_DiskDrive","WQL", $wbemFlagReturnImmediatley + $wbemFlagFowardOnly)
$colItems=$objWMIService^ERROR

Error: Variable must be of type "Object"

One is running Win XP, the other Win XP Pro (the 2 users getting the error). I have no clue why only 2 out of 500+ would get this error. I'm unable to reproduce it.

I'm not very well versed on the usage of WMI and what windows services it does or does not require. Could they have possibly "tweaked" their machine and turned off services which they felt they didn't need, resulting in possibly turning off the service(s) that WMI relies on, making those classes unavailable?

I'm totally in the dark on this one. Any help on this would be greatly appreciated.

Thanks in advance!

Michael

Edited by michael

Share this post


Link to post
Share on other sites



It would be possible that WMI queries are not working on the machines due to reasons like permissions, unavailable services, security settings etc. It would be useful if you can post the complete script here.

However if you don't want your scripts to crash in case the WMI queries could not be executed, then use the IsObj() function to check if the variable is a valid object before calling any functions from it.

Share this post


Link to post
Share on other sites

Thanks for the tip. However, in order for them to use my application, this *must* complete successfully.

Rather than detecting whether it is an object or not and then moving on in the script with or without the information, I'm looking for the root cause of the error and would hopefully be able to tell my user "you need to turn X service back on or install Y software in order to make it work."

Any ideas on this?

Share this post


Link to post
Share on other sites

Thanks for the tip. However, in order for them to use my application, this *must* complete successfully.

Rather than detecting whether it is an object or not and then moving on in the script with or without the information, I'm looking for the root cause of the error and would hopefully be able to tell my user "you need to turn X service back on or install Y software in order to make it work."

Any ideas on this?

I came across this error as well, while converting some code from an example and trying to run the script in a function and then try to use the same obj code in another function - it did not work. I had rewrite it so it did not use it, but it worked fine in the first function call. Maybe you are having the same problem. Take a look at this code.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:        Thorsten Meger <Thorsten.Meger@gmx.de>  & ...
;
; Script Function:
;   Windows XP Information displayed in a GUI
;   with Office-Key (only Office XP or 2003 supported)
;
; UPdated by nitekram on 032106 - OnEvent
;
; ----------------------------------------------------------------------------
;

#include-once
;Global variables
Global $product = ""; Office product Version (XP or 2003)
Global $counter = 3; Counter for progressBar
Global $wait = 150; Wait for progessBar

Global $description_I, $windowsType_I, $serialNumber_I, $ProductKey_I, $InstallDate_I, $LastBootUpTime_I, $RegisteredOwner_I, $officeKey_I, $officeKey_L

Global $objOperatingSystem, $colSettings, $Close

Global $Description_B, $status_L, $Bin, $key4RegisteredOwner, $GUI, $counter, $progressbar

Global $wait, $objWMIService
Global $exit_B, $WindowsType_B, $SerialNumber_B, $ProductKey_B, $InstallDate_B, $LastBootUpTime_B, $registeredOwner_B, $OfficeKey_B

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colSettings = $objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")



Func system()
    
;GUI
    $GUI = GUICreate("Windows Information", 685, 450, 250, 0)  ; 685, 450, 158, 127
    
;Labels
    $windowsInformation_L = GUICtrlCreateLabel("Windows Information", 8, 8, 659, 25)
    $status_L = GUICtrlCreateLabel("Information read out ...", 24, 80, 400, 17)
    $description_L = GUICtrlCreateLabel("Description", 16, 112, 103, 17)
    $windowsType_L = GUICtrlCreateLabel("WindowsType", 16, 152, 103, 17)
    $serialNumber_L = GUICtrlCreateLabel("SerialNumber", 16, 192, 103, 17)
    $ProductKey_L = GUICtrlCreateLabel("ProductKey", 16, 232, 103, 17)
    $InstallDate_L = GUICtrlCreateLabel("InstallDate", 16, 272, 103, 17)
    $LastBootUpTime_L = GUICtrlCreateLabel("LastBootUpTime", 16, 312, 103, 17)
    $RegisteredOwner_L = GUICtrlCreateLabel("RegisteredOwner", 16, 352, 103, 17)
    $officeKey_L = GUICtrlCreateLabel("OfficeKey", 16, 392, 103, 17)
    
;Input
    $description_I = GUICtrlCreateInput("Description", 130, 112, 389, 21)
    $windowsType_I = GUICtrlCreateInput("WindowsType", 130, 152, 389, 21)
    $serialNumber_I = GUICtrlCreateInput("SerialNumber", 130, 192, 389, 21)
    $ProductKey_I = GUICtrlCreateInput("ProductKey", 130, 232, 389, 21)
    $InstallDate_I = GUICtrlCreateInput("InstallDate", 130, 272, 389, 21)
    $LastBootUpTime_I = GUICtrlCreateInput("LastBootUpTime", 130, 312, 389, 21)
    $RegisteredOwner_I = GUICtrlCreateInput("RegisteredOwner", 130, 352, 389, 21)
    $officeKey_I = GUICtrlCreateInput("OfficeKey", 130, 392, 389, 21)
    
;Groups
    $informationPanel_G = GUICtrlCreateGroup("Information Panel", 8, 48, 585, 393)
    $status_G = GUICtrlCreateGroup("Status", 14, 64, 553, 41)
    $buttins_G = GUICtrlCreateGroup("Buttons", 608, 48, 65, 393)
    $office_G = GUICtrlCreateGroup("Microsoft Office", 14, 375, 553, 48)
    
    
;Buttons
    $exit_B = GUICtrlCreateButton("Exit", 616, 72, 49, 25, 0)
    GUICtrlSetOnEvent($exit_B, "CLOSEIT")
    $Description_B = GUICtrlCreateButton("clipboard", 616, 112, 49, 25, 0)
    GUICtrlSetOnEvent($Description_B, "CLOSEIT")
    $WindowsType_B = GUICtrlCreateButton("clipboard", 616, 152, 49, 25, 0)
    GUICtrlSetOnEvent($WindowsType_B, "CLOSEIT")
    $SerialNumber_B = GUICtrlCreateButton("clipboard", 616, 192, 49, 25, 0)
    GUICtrlSetOnEvent($SerialNumber_B, "CLOSEIT")
    $ProductKey_B = GUICtrlCreateButton("clipboard", 616, 232, 49, 25, 0)
    GUICtrlSetOnEvent($ProductKey_B, "CLOSEIT")
    $InstallDate_B = GUICtrlCreateButton("clipboard", 616, 272, 49, 25, 0)
    GUICtrlSetOnEvent($InstallDate_B, "CLOSEIT")
    $LastBootUpTime_B = GUICtrlCreateButton("clipboard", 616, 312, 49, 25, 0)
    GUICtrlSetOnEvent($LastBootUpTime_B, "CLOSEIT")
    $registeredOwner_B = GUICtrlCreateButton("clipboard", 616, 352, 49, 25, 0)
    GUICtrlSetOnEvent($registeredOwner_B, "CLOSEIT")
    $OfficeKey_B = GUICtrlCreateButton("clipboard", 616, 392, 49, 25, 0)
    GUICtrlSetOnEvent($OfficeKey_B, "CLOSEIT")
    
; SetFont
    $font = "Comic Sans MS"
    GUICtrlSetFont($windowsInformation_L, 16, 400, 4, $font)
    
;ProgressBar
    $progressbar = GUICtrlCreateProgress(140, 75, 400, 25)
    GUISetState(@SW_SHOW)
    
    $Close = GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEIT")
    
    createBAR()
    
EndFunc  ;==>system





Func createBAR()
    
    While $counter <> - 2
    ;$msg = GUIGetMsg()
        If $counter = 3 Then
            Sleep(500)
            GUICtrlSetData($status_L, "Initialize... " & $counter)
            progress()
            $counter -= 1
        ElseIf $counter = 2 Then
            GUICtrlSetData($status_L, "Initialize... " & $counter)
            progress()
            $counter -= 1
        ElseIf $counter = 1 Then
            GUICtrlSetData($status_L, "Initialize... " & $counter)
            progress()
            $counter -= 1
        ElseIf $counter = 0 Then
            GUICtrlSetData($status_L, "Ready ...")
            progress()
            $counter -= 1
        ElseIf $counter = -1 Then
            Dim $Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductID")
            Dim $key4RegisteredOwner = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
            
            
        ;; right here i took out
            #cs
                $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
                $colSettings = $objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
            #ce
            For $objOperatingSystem In $colSettings
            Next
            GUICtrlSetData($description_I, StringMid($objOperatingSystem.Description, 1))
            GUICtrlSetData($windowsType_I, '(' & @OSVersion & ') ' & StringMid($objOperatingSystem.Caption, 19))
            GUICtrlSetData($serialNumber_I, StringMid($objOperatingSystem.SerialNumber, 1))
            GUICtrlSetData($ProductKey_I, DecodeProductKey($Bin))
            GUICtrlSetData($InstallDate_I, WMIDateStringToDate($objOperatingSystem.InstallDate))
            GUICtrlSetData($LastBootUpTime_I, WMIDateStringToDate($objOperatingSystem.LastBootUpTime))
            GUICtrlSetData($RegisteredOwner_I, RegRead($key4RegisteredOwner, "RegisteredOwner"))
            GUICtrlSetData($officeKey_I, getOfficeKey())
            GUICtrlSetData($officeKey_L, "Office " & $product)
            $counter -= 1
        EndIf
    WEnd
EndFunc  ;==>createBAR

Func CLOSEIT()
    
;tester()
    
    If @GUI_CtrlId = $exit_B Then
        exit_b()
    ElseIf @GUI_CtrlId = $Description_B Then
        ClipPut(GUICtrlRead($description_I))
    ;ClipPut(StringMid($objOperatingSystem.Description, 1)); did not work something about an obj variable
        GUICtrlSetData($status_L, "Description copied to clipboard")
    ElseIf @GUI_CtrlId = $WindowsType_B Then
        ClipPut(GUICtrlRead($windowsType_I))
;ClipPut('(' & @OSVersion & ') ' & StringMid($objOperatingSystem.Caption, 19))
        GUICtrlSetData($status_L, "WindowsType copied to clipboard")
    ElseIf @GUI_CtrlId = $SerialNumber_B Then
        ClipPut(GUICtrlRead($serialNumber_I))
;ClipPut(StringMid($objOperatingSystem.SerialNumber, 1))
        GUICtrlSetData($status_L, "SerialNumber copied to clipboard")
    ElseIf @GUI_CtrlId = $ProductKey_B Then
        ClipPut(GUICtrlRead($ProductKey_I))
;ClipPut(DecodeProductKey($Bin))
        GUICtrlSetData($status_L, "ProductKey copied to clipboard")
    ElseIf @GUI_CtrlId = $InstallDate_B Then
        ClipPut(GUICtrlRead($InstallDate_I))
;ClipPut(WMIDateStringToDate($objOperatingSystem.InstallDate))
        GUICtrlSetData($status_L, "InstallDate copied to clipboard")
    ElseIf @GUI_CtrlId = $LastBootUpTime_B Then
        ClipPut(GUICtrlRead($LastBootUpTime_I))
;ClipPut(WMIDateStringToDate($objOperatingSystem.LastBootUpTime))
        GUICtrlSetData($status_L, "LastBootUpTime copied to clipboard")
    ElseIf @GUI_CtrlId = $registeredOwner_B Then
        ClipPut(GUICtrlRead($RegisteredOwner_I))
    ;ClipPut(RegRead($key4RegisteredOwner, "RegisteredOwner"))
        GUICtrlSetData($status_L, "RegisteredOwner copied to clipboard")
    ElseIf @GUI_CtrlId = $OfficeKey_B Then
        ClipPut(GUICtrlRead($officeKey_I))
    ;ClipPut(getOfficeKey())
        GUICtrlSetData($status_L, "OfficeKey copied to clipboard")
    ElseIf $GUI_EVENT_CLOSE = -3 Then
        GUIDelete(@GUI_WinHandle)
    EndIf
    
EndFunc  ;==>CLOSEIT



Func exit_b()
    GUICtrlSetData($status_L, "Have a GREAT DAY!")
    Sleep(1500)
    GUIDelete(@GUI_WinHandle)
EndFunc  ;==>exit_b


; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:        Unknown & Thorsten Meger <Thorsten.Meger@gmx.de>
;
; Script Function: Decode REG_BINARY
; ----------------------------------------------------------------------------

Func DecodeProductKey($BinaryDPID)
    Local $bKey[15]
    Local $sKey[29]
    Local $Digits[24]
    Local $Value = 0
    Local $hi = 0
    Local $n = 0
    Local $i = 0
    Local $dlen = 29
    Local $slen = 15
    Local $Result
    
    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
    $BinaryDPID = StringMid($BinaryDPID, 105, 30)
    For $i = 1 To 29 Step 2
        $bKey[Int($i / 2) ] = Dec(StringMid($BinaryDPID, $i, 2))
    Next
    For $i = $dlen - 1 To 0 Step - 1
        If Mod(($i + 1), 6) = 0 Then
            $sKey[$i] = "-"
        Else
            $hi = 0
            For $n = $slen - 1 To 0 Step - 1
                $Value = BitOR(BitShift($hi, -8), $bKey[$n])
                $bKey[$n] = Int($Value / 24)
                $hi = Mod($Value, 24)
            Next
            $sKey[$i] = $Digits[$hi + 1]
        EndIf
    Next
    For $i = 0 To 28
        $Result = $Result & $sKey[$i]
    Next
    Return $Result
EndFunc  ;==>DecodeProductKey

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:        Unknown & Thorsten Meger <Thorsten.Meger@gmx.de>
;
; Script Function: WMIDateStringToDate (changed Date format)
; ----------------------------------------------------------------------------

Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 7, 2) & "/" & _
            StringMid($dtmDate, 5, 2) & "/" & StringLeft($dtmDate, 4) _
             & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2))
EndFunc  ;==>WMIDateStringToDate

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:        Thorsten Meger <Thorsten.Meger@gmx.de>
;
; Script Function: Display a "fake" progressbar at the beginning
; ----------------------------------------------------------------------------

Func progress()
    If $counter = 3 Then
        For $i = 0 To 20 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 20)
        Next
    ElseIf $counter = 2 Then
        For $i = 20 To 50 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 30)
        Next
    ElseIf $counter = 1 Then
        For $i = 50 To 80 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 30)
        Next
    ElseIf $counter = 0 Then
        For $i = 80 To 100 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 20)
        Next
        GUICtrlSetState($progressbar, $GUI_HIDE)
    EndIf
EndFunc  ;==>progress

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author:        Thorsten Meger <Thorsten.Meger@gmx.de>
;
; Script Function:Get & decode OfficeKey
; ----------------------------------------------------------------------------

Func getOfficeKey()
    Local $List[1]
    Local $i = 1
    $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot", "Path")
    If $var <> "" Then
        $product = "2003"
        Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration"
    Else
        $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot", "Path")
        If @error <> 0 Then
            GUICtrlSetData($status_L, "Info: Unable to find installationPath, maybe no Office installed!")
            Return "No Office XP or 2003 found"
        EndIf
        If $var <> "" Then
            $product = "XP"
            Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Registration"
        EndIf
    EndIf
    Dim $var = RegEnumKey($officeKey, $i)
    If @error <> 0 Then
        GUICtrlSetData($status_L, "Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Return "No Office XP or 2003 found"
    Else
        $List[$i - 1] = RegRead($officeKey & "\" & $var, "DigitalProductID")
        If $List[$i - 1] = "" Then
            GUICtrlSetData($status_L, "Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Else
            $key = $List[$i - 1]
            Return DecodeProductKey($key)
        EndIf
    EndIf
EndFunc  ;==>getOfficeKey

If you find out the answer let me know - I would like to be able to use in the future. Anyway if you take out the comments in the closeit() you will get the same type of error. I am not sure if it helps you but maybe your issue is the same and someone can look at this code.

;ClipPut(StringMid($objOperatingSystem.Description, 1)) ; did not work something about an obj variable


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

:mellow: Office & Win key's WORKING!

It's my first post (in English), carefully please...

$key = ""

Dim $Bin
$Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductID")
    MsgBox(4096, "WinDows Key: " , "PID: " & RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductId") & @CRLF & "Key: " & DecodeProductKey($bin) )


Dim $Bin
$Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration","DigitalProductId")
    MsgBox(4096, "IE Key: " , "PID: " & RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "ProductId") & @CRLF & "Key: " & DecodeProductKey($bin) )

For $i= 1 to 10
    $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office", $i)
    If @error <> 0 then ExitLoop
    RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\" & $var & "\Registration", 1)
    If @error == 0 then
    $key = $var
    ExitLoop
    EndIf
Next

if $key then
For $i= 1 to 10
    $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\" & $key & "\Registration", $i)
    If @error <> 0 then ExitLoop
    $num = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\" & $key & "\Registration\" & $var, "ProductName")
    $num1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\" & $key & "\Registration\" & $var, "ProductID")
    Dim $Bin
    $Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\" & $key & "\Registration\" & $var,"DigitalProductId")
    MsgBox(4096, "Office:" , $num & " (" & $key & ") " & @CRLF & "PID: " & $num1 & @CRLF & "Key: " & DecodeProductKey($bin) )
Next
Else
MsgBox(16, "", "Not Find any M$ Office in this System :-(")
EndIf

    MsgBox(64, "Info", "That's ALL :-)")

Func DecodeProductKey($BinaryDPID)
   Local $bKey[15]
   Local $sKey[29]
   Local $Digits[24]
   Local $Value = 0
   Local $hi = 0
   local $n = 0
   Local $i = 0
   Local $dlen = 29
   Local $slen = 15
   Local $Result

   $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789","")

   $binaryDPID = stringmid($binaryDPID,105,30)

   For $i = 1 to 29 step 2
       $bKey[int($i / 2)] = dec(stringmid($binaryDPID,$i,2))
   next

   For $i = $dlen -1 To 0 Step -1
       If Mod(($i + 1), 6) = 0 Then
           $sKey[$i] = "-"
       Else
           $hi = 0
           For $n = $slen -1 To 0 Step -1
               $Value = Bitor(bitshift($hi ,- 8) , $bKey[$n])
               $bKey[$n] = int($Value / 24)
               $hi = mod($Value , 24)
           Next
           $sKey[$i] = $Digits[$hi +1]
       EndIf

   Next
   For $i = 0 To 28
       $Result = $Result & $sKey[$i]
   Next

   Return $Result
EndFunc

or see Office_WinKey_s_.au3.

P.S. Working with: WinXP SP2; Office 2003 & Office XP (TESTED!) :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0