Jump to content
Sign in to follow this  
pendragon

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

Recommended Posts

pendragon

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

Share this post


Link to post
Share on other sites
pendragon

Nice..thanks for that.

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

Share this post


Link to post
Share on other sites
Henri

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

Share this post


Link to post
Share on other sites
trancexx

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

Share this post


Link to post
Share on other sites
Henri

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.

Share this post


Link to post
Share on other sites
wakillon

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

Share this post


Link to post
Share on other sites
Confuzzled

Problem is you're using the object before you test if it created successfully, hence the (valid) error. Error checking is the mark of a wise coder...

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.