Jump to content

Line -1: Error:Variable must be of type "Object".


Recommended Posts

Hi,

I'm new to this, and I'm a bit stumped on this.

I'm trying to use autoit to check devices for a battery, unfortunatley, when I run this on a computer that doesn't have a battery, it spits out the following:

AutoIT Error

Line -1:

Error: Variable must be of the type "Object".

How can I avoid/hide this error when the script runs against devices without a battery? When the code is executed on a device with a battery, it functions fine.

The code:

Dim $sAns

$WMI = ObjGet("WinMgmts:")

$objs = $WMI.InstancesOf("Win32_Battery")

$iCount = 1

For $obj In $objs

$sAns = $sAns & $obj.Caption

If $iCount < $objs.Count Then $sAns = $sAns & ","

$iCount += 1

Next

If $obj.Caption <> 'Internal Battery' Then Msgbox(0,"Yay","It works!")

If anyone can help, I'd appreciate it

Link to comment
Share on other sites

  • 1 year later...

Hi,

Actually I have the same problem on a Windows7 machine. But I can't run the AutoIt file because of the same error.

Can you tell me where is this file that I should modify?

Thanks

In your head ...which for some reason you refuse to use. Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

That's what I thaught,but impossible to find it. It's quite empty up there.

Seriously the thing is that I had an .exe file created while I installed VMWareRawc Desktop Launcher.

The thing is that as in the AutoIT Eula it's specified that you can't uncompile the .exe file. So I wonder if someone has the same problem than me, or if I'm just fucked.

By the way, that's true, I thaught you were a boy.

Link to comment
Share on other sites

  • 1 month later...

Try to check if it's a laptop...Posted Image

If Not _IsLaptopPC ( ) Then Exit MsgBox ( 4096, "Error", "It's not a LapTop PC", 6 )

Func _IsLaptopPC ( $_myComputer='.' )
    $_objWMIService = ObjGet ( "winmgmts://" & $_myComputer & "/root/cimv2" )
    $_colItems = $_objWMIService.ExecQuery ( "Select * from Win32_Battery" )
    For $_objItem in $_colItems
        If $_objItem <> '' Then Return True
    Next
    Return False
EndFunc ;==> _IsLaptopPC ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

  • 3 weeks later...

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...