Broots Posted July 12, 2006 Posted July 12, 2006 Hi,My first post, and it's because I can't understand simple logic! I am trying to convert a simple piece of WMI Code to use in AutoIT. However, I just can't seem to work out what I need to change. I've never done programming, and am still trying to get to grips with when to use the Do, For, While commands. What I am trying to do, is to write a small application that detects when a computer has connected or disconnected from a network using any of it's interfaces so that other settings can be effected. From the Microsoft Scripting Guy Column here, there are two scripts that can used.This is for when a disconnect is detectedstrComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("Select * from MSNdis_StatusMediaDisconnect") Do While True Set strLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo "A network connection has been lost:" WScript.Echo strLatestEvent.InstanceName, Now Wscript.Echo LoopThis is for detecting when a connection is madestrComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("Select * from MSNdis_StatusMediaConnect") Do While True Set strLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo "A network connection has been made:" WScript.Echo strLatestEvent.InstanceName, Now Wscript.Echo LoopThis is my AutoIT code, which i've tried to write which doesn't work; Generated by AutoIt Scriptomatic $APP = "NetSentry" $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $objNicMonitorService = ObjGet("winmgmts:\\" & $strComputer & "\root\WMI") $colItems = $objNicMonitorService.ExecQuery("SELECT * FROM MSNdis_StatusMediaDisconnect") If IsObj($colItems) Then For $objItem in $colItems While 1 $strLatestEvent = $ColItems.NextEvent $Output = "A network connection has been lost:" & @CRLF $Output = $Output & $strLatestEvent.InstanceName TrayTip($APP,"Disconnect Detected. Updating Networks", 5) WEnd Next Else EndIfMy Questions1) What is the AutoIT equivalent of Do While True ? 2) How can I write a WQL query to poll for both events so that it can run in a loop. I've tried various WMI queries, and it just doesn't work. I don't think WMI can query two differenct 'classes' simulataneously.3) You guys are great! I'm just not clever enough to transplant the knowledge I've tried to learn while searching the other posts.
MHz Posted July 12, 2006 Posted July 12, 2006 My Questions1) What is the AutoIT equivalent of Do While True ?While True...WEnd.VBScript still uses While WEnd but M$ recommends using Do While...Loop as While can be used at top or at the bottom as Do...Loop While. The latter is the same as AutoIt's Do...Until2) How can I write a WQL query to poll for both events so that it can run in a loop. I've tried various WMI queries, and it just doesn't work. I don't think WMI can query two differenct 'classes' simulataneously.Never seen it done to know. 3) You guys are great! I'm just not clever enough to transplant the knowledge I've tried to learn while searching the other posts.I cannot do transplants but would recommend a copy of AutoIt's version of Scriptomatic from Scripts'n'Scraps forum for WMI stuff. Also download a copy of VBScript's Helpfile at M$ (Script56.chm) for the help with understanding the loops and the rest.
Broots Posted July 12, 2006 Author Posted July 12, 2006 While True...WEnd.VBScript still uses While WEnd but M$ recommends using Do While...Loop as While can be used at top or at the bottom as Do...Loop While. The latter is the same as AutoIt's Do...UntilNever seen it done to know. I cannot do transplants but would recommend a copy of AutoIt's version of Scriptomatic from Scripts'n'Scraps forum for WMI stuff. Also download a copy of VBScript's Helpfile at M$ (Script56.chm) for the help with understanding the loops and the rest.Thanks for the info. Will try to research and resolve. If anybody else has ideas on the Looping two WMI queries, would appreciate it!
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