Sign in to follow this  
Followers 0
BoyNarf

WMIService ERROR Variable Must Be Of Type "Object"

9 posts in this topic

Hello Everyone,

I am trying to convert an old VBScript into AutoIT and am having some issue. I tried the conversion tool available on this forum but it did not work. I am slowly going through the code and fixing all of the errors. This, however, is one that I can't seem to get working... It keeps throwing the ERROR: Variable must be of type "object" error. I have tried a variety of different methods found on this forum, but I keep getting the same error.

thanks,

Dim $strcomputer = "139.48.85.90"

Dim $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strcomputer & "\root\cimv2")

Dim $colSettings = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

For $objComputer in $colSettings

$CompName = $objComputer.Name

$UserName = $objComputer.UserName

Next

msgbox(1,"","Computer Name: " & $CompName & @CRLF & _

"Username: " & $UserName)

Share this post


Link to post
Share on other sites



If IsObj($colSettings) Then
For $objComputer in $colSettings
$CompName = $objComputer.Name
$UserName = $objComputer.UserName
Next
Else
    MsgBox(4096, "ERROR", "Failed to connect to WMI at: " & $colSettings)
    EndIf

You also may want to declare your variables as Global

Share this post


Link to post
Share on other sites

Unless the variable is inside a function, they're automatically declared Global, but still it's a good practice to get into whereby you explicitly declare your variables.

BTW, the DIM statement is deprecated in favor of Global or Local.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I have changed the Dim to Global and thrown that "IF Logic" into my code, but I still get the same error... Am I missing a variable declaration somewhere?

It seems to be having problems with this line...

Global $colSettings = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

Share this post


Link to post
Share on other sites

Is it possible that there is an error in the computer IP address you're trying to reach? Or is it possible that you don't have the rights to get the information from it that you're trying to get? Have you tried getting the information using the computer name rather than the IP address?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I am actually using the computer name. I just put in the IP adress for demo purposes. I also have full access to the PC as well...

Share this post


Link to post
Share on other sites

I have also tried running the script logged in under a different user, and also logged into a different domain. I keep getting the same object error.

Share this post


Link to post
Share on other sites

I ran your script with some computer names that are on the domain where I work and was able to pull up the information as long as the computer was turned on and reachable through the network. The only time it failed was when the computer either didn't exist (mistyped the name) or it has been shut off/put to sleep.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

strange...

I have tried multiple computer names and they are in fact turned on. It only seems to work locally for me... I do some more testing.

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