Jump to content
Sign in to follow this  
Emiel Wieldraaijer

Problem with autodetecting drive/disk plugin

Recommended Posts

Hi All,

I use the following script to automatic add drives plugged in after starting a GUI.

But on some computers the program exits with an AutoIt Error and it's caused by the following line

$objWMIServices.ExecNotificationQueryAsync ($sink, "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " & "TargetInstance ISA 'Win32_LogicalDisk'")

Does the above line depend on a specified service or something else ?

For Example this script will not work with a windows installation installed by 'Windows "Arium" 3005 (May 2011 : 644Mo)' Download -> http://depositfiles.com/files/rb0vfsg8k

Thanks

Best regards,

Emiel

#Region
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Add_Constants=n
#EndRegion
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#Include <GuiListView.au3>
Dim $Drive_Set, $LVItems[30]
Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES,$LVS_EX_CHECKBOXES)
$strComputer = "."
$objWMIServices = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$sink = ObjCreate("WbemScripting.SWbemSink")
ObjEvent($sink,"SINK_")
$objWMIServices.ExecNotificationQueryAsync ($sink, "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " & "TargetInstance ISA 'Win32_LogicalDisk'")
$Parent = GUICreate("DriveList", 520, 320)
$list = GUICtrlCreateListView("", 30, 30, 460, 260, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($list, $exStyles)
GUISetState ()
_GUICtrlListView_AddColumn($list, "Drive", 75)
_GUICtrlListView_AddColumn($list, "Used", 92)
_GUICtrlListView_AddColumn($list, "Free", 92)
_GUICtrlListView_AddColumn($list, "Type", 75)
_GUICtrlListView_AddColumn($list, "Label",112)
_ListViewDiskInformation ()
_ListViewSetDiskInformation ()
While 1
$msg = GuiGetMsg()
Switch $msg
  Case -3
   Exit
  Case -100 To 0
   ContinueLoop
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
Wend
Func _ListViewRenew ()
_GUICtrlListView_DeleteAllItems($list)
_ListViewDiskInformation ()
_ListViewSetDiskInformation ()
EndFunc
Func _ListViewDiskInformation ()
$Drive_Set = ""
$DriveList = ""
$Drive_Set = DriveGetDrive("ALL")
EndFunc
Func SINK_OnObjectReady($objObject, $objAsyncContext)
If $objObject.TargetInstance.DriveType = 2 Then
        Select
            Case $objObject.Path_.Class()="__InstanceCreationEvent"
    _ListViewRenew ()
            Case $objObject.Path_.Class()="__InstanceDeletionEvent"
    _ListViewRenew ()
        EndSelect
    EndIf
EndFunc
Func _ListViewSetDiskInformation ()
For $i = 1 To $drive_set[0]
  $DriveType = DriveGetType($drive_set[$i])
  $totals = Round(DriveSpaceTotal($drive_set[$i]) / 1024, 1)
  $spacef = Round(DriveSpaceFree($drive_set[$i]) / 1024, 1)
  $spaceu = Round(($totals - $spacef), 1)
  $LVItems[$i] = GUICtrlCreateListViewItem(StringUpper($drive_set[$i]) & "|" & $spaceu & " GB" & "|" & $spacef & " GB" & "|" & DriveGetFileSystem($drive_set[$i]) & "|" & DriveGetLabel($drive_set[$i]), $list)
Next
EndFunc

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

I bet you did not install the image and take a look if the service is started .. because you would see this will not work even when the WMI service is started

It worked for me. I will not install anything I don't trust off of deposit files. Especially with a potentially hacked WMI.

You might want to see the following.

http://windowsxp.mvps.org/repairwmi.htm

Edited by DicatoroftheUSA

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...