Sign in to follow this  
Followers 0
hacky1978

Intercept error in WMI connect when username or password is wrong

3 posts in this topic

Hello,

i need the last reboot time of remote maschines. I have realized this in autoit but in case of a wrong username or password the script stops with error "The request action with this object has failed".

This only occurs when the used useraccount is wrong. But the script should go on without any message...

Can you help me?

Global $s_ComputerName = remotehost

Global $s_AdminUser = "Administrator"

Global $s_AdminLocPW = "Password"

$o_SWbemLocator = ObjCreate("WbemScripting.SWbemLocator")

$o_WMIService = $o_SWbemLocator.ConnectServer($s_ComputerName, "root\CIMV2", $s_AdminUser, $s_AdminLocPW)

$o_ItemCollection = $o_WMIService.ExecQuery("SELECT LastBootUpTime FROM Win32_OperatingSystem", "WQL", 48)

For $objItem In $o_ItemCollection

$lastboot=$objItem.LastBootUpTime

Next

Greetings,

Hacky1978

Share this post


Link to post
Share on other sites



You need a COM error handler or the latest beta of AutoIt.

Check ObjEvent to see how to write a COM error handler.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

.... an example on how to handle wmi errors is here:

bye


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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