pendragon Posted August 27, 2008 Share Posted August 27, 2008 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 ErrorLine -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 = 1For $obj In $objs $sAns = $sAns & $obj.CaptionIf $iCount < $objs.Count Then $sAns = $sAns & ","$iCount += 1NextIf $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 More sharing options...
Zedna Posted August 27, 2008 Share Posted August 27, 2008 If IsObj($obj) And $obj.Caption <> 'Internal Battery' Then Msgbox(0,"Yay","It works!") Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
pendragon Posted August 28, 2008 Author Share Posted August 28, 2008 Nice..thanks for that. If IsObj($obj) And $obj.Caption <> 'Internal Battery' Then Msgbox(0,"Yay","It works!") Link to comment Share on other sites More sharing options...
Henri Posted August 23, 2010 Share Posted August 23, 2010 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 Link to comment Share on other sites More sharing options...
trancexx Posted August 23, 2010 Share Posted August 23, 2010 (edited) 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? ThanksIn your head ...which for some reason you refuse to use. Edited August 23, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Henri Posted August 23, 2010 Share Posted August 23, 2010 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 More sharing options...
wakillon Posted September 24, 2010 Share Posted September 24, 2010 Try to check if it's a laptop...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.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Confuzzled Posted October 9, 2010 Share Posted October 9, 2010 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... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now