Platforms to show: All Mac Windows Linux Cross-Platform

/Win/USB Stick to Drive Letter


Required plugins for this example: MBS Win Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/USB Stick to Drive Letter

This example is the version from Sun, 24th Jan 2015.

Project "USB Stick to Drive Letter.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() // must be done before first window opens! call WindowsWMIMBS.InitSecurity(false) End EventHandler
End Class
Class Window1 Inherits Window
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() listbox1.DeleteAllRows if not TargetWin32 then MsgBox "This example is for Windows only." Return end if dim w1 as new WindowsWMIMBS dim w2 as new WindowsWMIMBS dim w3 as new WindowsWMIMBS // connect three objects, so we can query in parallel if not w1.ConnectServer("root\cimv2") or not w2.ConnectServer("root\cimv2") or not w3.ConnectServer("root\cimv2") then MsgBox "ConnectServer: fail"+EndOfLine+"Lasterror: "+str(w1.Lasterror) Return end if // look for USB Devices dim query1 as string = "select * from Win32_DiskDrive where InterfaceType='USB'" System.DebugLog query1 if not w1.query("WQL", query1) then System.DebugLog str(w1.Lasterror)+" "+hex(w1.Lasterror)+": "+w1.LasterrorMessage MsgBox "query: fail"+EndOfLine+"Lasterror: "+str(w1.Lasterror) Return end if dim Volumes() as string // loop over USB devices while w1.NextItem dim DeviceID as string = w1.GetProperty("DeviceID") dim Description as string = w1.GetProperty("Description") dim PNPDeviceID as string = w1.GetProperty("PNPDeviceID") dim SerialNumber as string = w1.GetProperty("SerialNumber") dim Size as string = w1.GetProperty("Size") dim Status as string = w1.GetProperty("Status") Listbox1.AddRow "DeviceID", DeviceID Listbox1.AddRow "Description", Description Listbox1.AddRow "PNPDeviceID", PNPDeviceID Listbox1.AddRow "SerialNumber", SerialNumber Listbox1.AddRow "Size", Size Listbox1.AddRow "Status", Status // look for Disks dim query2 as string = "Associators of {Win32_DiskDrive.DeviceID='"+DeviceID+"'} where AssocClass=Win32_DiskDriveToDiskPartition" System.DebugLog query2 if not w2.query("WQL", query2) then System.DebugLog str(w2.Lasterror)+" "+hex(w2.Lasterror)+": "+w2.LasterrorMessage MsgBox "query: fail"+EndOfLine+"Lasterror: "+str(w2.Lasterror) Return end if while w2.NextItem dim DiskDeviceID as string = w2.GetProperty("DeviceID") dim DiskSize as string = w2.GetProperty("Size") Listbox1.AddRow "DiskDeviceID", DiskDeviceID Listbox1.AddRow "DiskSize", DiskSize // look for logical volumes dim query3 as string = "Associators of {Win32_DiskPartition.DeviceID='"+DiskDeviceID+"'} where AssocClass=Win32_LogicalDiskToPartition" System.DebugLog query3 if not w3.query("WQL", query3) then System.DebugLog str(w3.Lasterror)+" "+hex(w3.Lasterror)+": "+w3.LasterrorMessage MsgBox "query: fail"+EndOfLine+"Lasterror: "+str(w3.Lasterror) Return end if while w3.NextItem dim VolumeDeviceID as string = w3.GetProperty("DeviceID") dim VolumeDescription as string = w3.GetProperty("Description") dim VolumeName as string = w3.GetProperty("VolumeName") dim VolumeSize as string = w3.GetProperty("Size") dim FileSystem as string = w3.GetProperty("FileSystem") dim FreeSpace as string = w3.GetProperty("FreeSpace") Listbox1.AddRow "VolumeDeviceID", VolumeDeviceID Listbox1.AddRow "VolumeDescription", VolumeDescription Listbox1.AddRow "VolumeName", VolumeName Listbox1.AddRow "VolumeSize", VolumeSize Listbox1.AddRow "FileSystem", FileSystem Listbox1.AddRow "FreeSpace", FreeSpace Volumes.Append VolumeDeviceID wend wend Listbox1.AddRow "" wend listbox1.AddRow "Found volumes:", Join(Volumes, ", ") End EventHandler
End Control
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

The items on this page are in the following plugins: MBS Win Plugin.


The biggest plugin in space...