wraithdu Posted October 29, 2008 Share Posted October 29, 2008 Does anyone have an idea why this would work in Vista and not in XP? MSDN says all the methods and classes are supported in XP. The events should be triggered on addition and removal of volumes, such as USB disk devices. Any help is appreciated. $wmiSink = ObjCreate("WbemScripting.SWbemSink") ObjEvent($wmiSink , "SINK_") $Obj_WMIService = ObjGet('winmgmts:\\localhost\root\cimv2') If Not @error Then $obj_WMIService.ExecNotificationQueryAsync($wmiSink, "SELECT * FROM Win32_VolumeChangeEvent") ConsoleWrite("Ready and waiting for changes" & @CRLF) EndIf While 1 Sleep(1000) WEnd Func SINK_OnObjectReady($objLatestEvent, $objAsyncContext) ConsoleWrite("Sink event." & @CRLF) ; Events: ; 1 = Configuration Changed ; 2 = Device Arrival ; 3 = Device Removal ; 4 = Docking ConsoleWrite($objLatestEvent.DriveName & @CRLF) ConsoleWrite($objLatestEvent.EventType & @CRLF) EndFunc ;==>SINK_OnObjectReady Link to comment Share on other sites More sharing options...
arcker Posted October 30, 2008 Share Posted October 30, 2008 (edited) don't say it's not working this class is for notification event. Don't think its for async purpose. maybe us the class win32_diskdrive with this query : SELECT * FROM __InstanceOperationEVENT WITHIN 1 WHERE TargetInstance ISA 'Win32_DiskDrive' and adapt the output. Edited October 30, 2008 by arcker -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
wraithdu Posted October 30, 2008 Author Share Posted October 30, 2008 (edited) Right, it's an event notification class, and I'm using ExecNotificationQueryAsync to get async notifications. It works perfectly on Vista, just not XP. MSDN says nothing about the classes being different or operating differently under XP vs Vista. I'll have to check out your alternative later. What kind of query are you using with that? ExecQuery, ExecNotificationQuery, ...? Edited October 30, 2008 by wraithdu Link to comment Share on other sites More sharing options...
arcker Posted October 30, 2008 Share Posted October 30, 2008 the query i've given if for ExecNotificationQueryAsync. DiskDrive Class can return DevicdID, but then you have to get the drive letter by using functions that you used in your eject usb script ( or use wmi, but that's really slower ). I think a monitoring is possible by questionning the device manager every second, as wmi do. -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
wraithdu Posted October 30, 2008 Author Share Posted October 30, 2008 Hmm, interesting comment at the bottom here -http://msdn.microsoft.com/en-us/library/aa394516(VS.85).aspxAnd an alternative here -http://www.microsoft.com/technet/scriptcen...06/hey0213.mspx Link to comment Share on other sites More sharing options...
wraithdu Posted October 30, 2008 Author Share Posted October 30, 2008 @arcker Thanks for the direction. Here's a working script for Vista and XP. expandcollapse popup$wmiSink = ObjCreate("WbemScripting.SWbemSink") ObjEvent($wmiSink , "SINK_") $Obj_WMIService = ObjGet('winmgmts:\\localhost\root\cimv2') If Not @error Then $obj_WMIService.ExecNotificationQueryAsync($wmiSink, "SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_LogicalDisk'") ConsoleWrite("Ready and waiting for changes" & @CRLF) EndIf While 1 Sleep(1000) WEnd Func SINK_OnObjectReady($objLatestEvent, $objAsyncContext) Switch $objLatestEvent.Path_.Class Case "__InstanceCreationEvent" ConsoleWrite("->==========================================" & @CRLF) ConsoleWrite("> Creation Event" & @CRLF) Case "__InstanceDeletionEvent" ConsoleWrite("->==========================================" & @CRLF) ConsoleWrite("> Deletion Event" & @CRLF) EndSwitch ; Access: ; 0 - Unknown ; 1 - Readable ; 2 - Writable ; 3 - Read / Write Supported ; 4 - Write Once Switch $objLatestEvent.Path_.Class Case "__InstanceCreationEvent", "__InstanceDeletionEvent" ConsoleWrite("Access: " & $objLatestEvent.TargetInstance.Access & @CRLF) ConsoleWrite("Caption: " & $objLatestEvent.TargetInstance.Caption & @CRLF) ConsoleWrite("Description: " & $objLatestEvent.TargetInstance.Description & @CRLF) ConsoleWrite("DeviceID: " & $objLatestEvent.TargetInstance.DeviceID & @CRLF) ConsoleWrite("DriveType: " & $objLatestEvent.TargetInstance.DriveType & @CRLF) ConsoleWrite("FileSystem: " & $objLatestEvent.TargetInstance.FileSystem & @CRLF) ConsoleWrite("FreeSpace: " & Int($objLatestEvent.TargetInstance.FreeSpace / 1000000) & " MB" & @CRLF) ConsoleWrite("Name: " & $objLatestEvent.TargetInstance.Name & @CRLF) ConsoleWrite("Size: " & Int($objLatestEvent.TargetInstance.Size / 1000000) & " MB" & @CRLF) ConsoleWrite("VolumeSerialNumber: " & $objLatestEvent.TargetInstance.VolumeSerialNumber & @CRLF) ConsoleWrite("->==========================================" & @CRLF) EndSwitch EndFunc ;==>SINK_OnObjectReady 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