Buffo Posted October 28, 2007 Share Posted October 28, 2007 Hi! I want to run a script in background that notifies a CD/DVD media replacement. How ist this to realize? If I use DriveStatus() the drive is always running on each query. Perhaps is there the possibiltiy to use WMI? I don't know I hope you can help me Thx in advance! Regards, Buffo Link to comment Share on other sites More sharing options...
doudou Posted October 29, 2007 Share Posted October 29, 2007 Windows sends WM_DEVICECHANGE message to all top level windows, whenever a removable media is inserted or removed (applies to CD/DVD as well as to USB-Drives etc.). If your script has a GUI (even hidden), you could try this: Const $DBT_DEVICEARRIVAL = 0x8000 ; system detected a new device Const $DBT_DEVICEQUERYREMOVE = 0x8001 ; wants to remove, may fail Const $DBT_DEVICEQUERYREMOVEFAILED = 0x8002 ; removal aborted Const $DBT_DEVICEREMOVEPENDING = 0x8003 ; about to remove, still avail. Const $DBT_DEVICEREMOVECOMPLETE = 0x8004 ; device is gone Const $DBT_DEVICETYPESPECIFIC = 0x8005 ; type specific event Const $WM_DEVICECHANGE = 0x0219 GUIRegisterMsg($WM_DEVICECHANGE, "MY_WM_DEVICECHANGE") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Wend Func MY_WM_DEVICECHANGE($hWnd, $msg, $wParam, $lParam) Switch $wParam Case $DBT_DEVICEARRIVAL ; do something Case $DBT_DEVICEREMOVECOMPLETE ; do something EndSwitch Return 1 EndFunc UDFS & Apps: Spoiler DDEML.au3 - DDE Client + ServerLocalization.au3 - localize your scriptsTLI.au3 - type information on COM objects (TLBINF emulation)TLBAutoEnum.au3 - auto-import of COM constants (enums)AU3Automation - export AU3 scripts via COM interfacesTypeLibInspector - OleView was yesterday Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCEĀ Link to comment Share on other sites More sharing options...
Buffo Posted October 29, 2007 Author Share Posted October 29, 2007 Thx for your reply Unfortunately this doesn't work... Has anyone other suggestions? Regards, Buffo Link to comment Share on other sites More sharing options...
doudou Posted October 29, 2007 Share Posted October 29, 2007 Unfortunately this doesn't work...Can you explain 'doesn't work'? What are you trying to do? Your code? UDFS & Apps: Spoiler DDEML.au3 - DDE Client + ServerLocalization.au3 - localize your scriptsTLI.au3 - type information on COM objects (TLBINF emulation)TLBAutoEnum.au3 - auto-import of COM constants (enums)AU3Automation - export AU3 scripts via COM interfacesTypeLibInspector - OleView was yesterday Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCEĀ Link to comment Share on other sites More sharing options...
Joon Posted October 29, 2007 Share Posted October 29, 2007 something to start... $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $oEvents = $oWMI.ExecNotificationQuery("SELECT * FROM Win32_DeviceChangeEvent") $oReceivedEvent = $oEvents.NextEvent ConsoleWrite('The event has occured.' & @LF) Link to comment Share on other sites More sharing options...
Buffo Posted October 29, 2007 Author Share Posted October 29, 2007 @doudou: It happens nothing if I change media or open and close my cd door My Code: #include <GUIConstants.au3> GuiCreate("", 600, 400) Const $DBT_DEVICEARRIVAL = 0x8000; system detected a new device Const $DBT_DEVICEQUERYREMOVE = 0x8001; wants to remove, may fail Const $DBT_DEVICEQUERYREMOVEFAILED = 0x8002; removal aborted Const $DBT_DEVICEREMOVEPENDING = 0x8003; about to remove, still avail. Const $DBT_DEVICEREMOVECOMPLETE = 0x8004; device is gone Const $DBT_DEVICETYPESPECIFIC = 0x8005; type specific event Const $WM_DEVICECHANGE = 0x0219 GUIRegisterMsg($WM_DEVICECHANGE, "MY_WM_DEVICECHANGE") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Wend Func MY_WM_DEVICECHANGE($hWnd, $msg, $wParam, $lParam) Switch $wParam Case $DBT_DEVICEARRIVAL MsgBox(0, "Arrival", "") Case $DBT_DEVICEREMOVECOMPLETE MsgBox(0, "Removecomplete", "") EndSwitch Return 1 EndFunc @Joon: I tried this: $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") While 1 $oEvents = $oWMI.ExecNotificationQuery("SELECT * FROM Win32_DeviceChangeEvent") $oReceivedEvent = $oEvents.NextEvent ConsoleWrite('The event has occured.' & @LF) Sleep(500) WEnd Nothing happens here, too. Regards, Buffo Link to comment Share on other sites More sharing options...
Joon Posted October 29, 2007 Share Posted October 29, 2007 Just making sure... Do you have actual CD in the drive? Empty CD Tray triggers nothing. Link to comment Share on other sites More sharing options...
Buffo Posted October 29, 2007 Author Share Posted October 29, 2007 Yes, media is inserted. Link to comment Share on other sites More sharing options...
doudou Posted October 29, 2007 Share Posted October 29, 2007 @doudou: It happens nothing if I change media or open and close my cd door Hmm, strange... Have you tried to show the main window just before entering GUIGetMsg() loop? GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg()... UDFS & Apps: Spoiler DDEML.au3 - DDE Client + ServerLocalization.au3 - localize your scriptsTLI.au3 - type information on COM objects (TLBINF emulation)TLBAutoEnum.au3 - auto-import of COM constants (enums)AU3Automation - export AU3 scripts via COM interfacesTypeLibInspector - OleView was yesterday Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCEĀ Link to comment Share on other sites More sharing options...
Buffo Posted October 30, 2007 Author Share Posted October 30, 2007 Yes, I tried but it doesn't work Link to comment Share on other sites More sharing options...
Buffo Posted November 1, 2007 Author Share Posted November 1, 2007 Now it works with GetDriveStatus(). I don't know why it didn't work before. The drive isn't spinning up any more. Thx to the guys at German AutoIt Forum Regards, Buffo 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