Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
Win32_DiskDrive WHERE InterfaceType='USB' not working ?
Logged in as: Guest
arrSession:exec spGetSession 2,2,49173
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
WSH & Client Side VBScript
>> Win32_DiskDrive WHERE InterfaceType='USB' not working ?
Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page:
[1]
Login
Message
<< Older Topic
Newer Topic >>
Win32_DiskDrive WHERE InterfaceType='USB' not working ? -
7/8/2007 5:46:44 PM
chapeau_melon
Posts: 17
Score: 0
Joined: 6/20/2007
Status:
offline
Hello,
Can you test this for me ? It is ought to work, but unfortunatly not with me :(
Could you tell me why ?
I can see it is accessing my usb sticks but it gives allways as a result 'no sticks'
Kind regards
'Find USB Stick Set dicUSBDrives = GetUSBDrives '--------------------------------------------------------------------------------------------------------------------------------------------------------------------- If dicUSBDrives.Count = 0 Then WScript.Echo "No USB sticks found!" Else WScript.Echo "Found a USB stick:" For Each strUSBDrive In dicUSBDrives WScript.Echo "Using" & strUSBDrive & "\" & "for Backup" Target = strUSBDrive & "\MyDocuments" Next End If '--------------------------------------------------------------------------------------------------------------------------------------------------------------------- Function GetUSBDrives ' Populate a dictionary object with USB drive letters Set dicUSBList = CreateObject("Scripting.Dictionary") dicUSBList.CompareMode = vbTextCompare strComputer = "." Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDiskDrives = objWMI.ExecQuery ("Select DeviceID from Win32_DiskDrive WHERE InterfaceType='USB'") For Each objDiskDrive In colDiskDrives strDeviceID = objDiskDrive.DeviceID strEscapedDeviceID = Replace(strDeviceID, "\", "\\") Set colDiskPartitions = objWMI.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & strEscapedDeviceID & """} WHERE " _ & "AssocClass = Win32_DiskDriveToDiskPartition") For Each objDiskPartition In colDiskPartitions Set colLogicalDisks = objWMI.ExecQuery ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _ objDiskPartition.DeviceID & """} WHERE " & _ "AssocClass = Win32_LogicalDiskToPartition") For Each objLogicalDisk In colLogicalDisks dicUSBList.Add objLogicalDisk.DeviceID, "" Next Next Next Set GetUSBDrives = dicUSBList End Function
< Message edited by
chapeau_melon
--
7/8/2007 5:50:19 PM
>
Post #: 1
RE: Win32_DiskDrive WHERE InterfaceType='USB' not worki... -
7/8/2007 6:41:06 PM
ginolard
Posts: 1082
Score: 21
Joined: 8/10/2005
Status:
offline
Try using Win32_LogicalDisk instead
'Find USB Stick Set dicUSBDrives = GetUSBDrives '--------------------------------------------------------------------------------------------------------------------------------------------------------------------- If dicUSBDrives.Count = 0 Then WScript.Echo "No USB sticks found!" Else WScript.Echo "Found a USB stick:" For Each strUSBDrive In dicUSBDrives WScript.Echo "Using" & strUSBDrive & "\" & "for Backup" Target = strUSBDrive & "\MyDocuments" Next End If '--------------------------------------------------------------------------------------------------------------------------------------------------------------------- Function GetUSBDrives ' Populate a dictionary object with USB drive letters Set dicUSBList = CreateObject("Scripting.Dictionary") dicUSBList.CompareMode = vbTextCompare strComputer = "." Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDiskDrives = objWMI.ExecQuery ("Select DeviceID from Win32_LogicalDisk WHERE DriveType=2") For Each objDiskDrive In colDiskDrives dicUSBList.Add objDiskDrive.DeviceID, "" Next Set GetUSBDrives = dicUSBList End Function
_____________________________
Author of ManagePC -
http://managepc.net
AD Query Template -
http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework -
http://www.visualbasicscript.com/m_59109/tm.htm
(in reply to
chapeau_melon
)
Post #: 2
If you found our site useful please link to us
<a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>
.
All Forums
>>
[Scripting]
>>
WSH & Client Side VBScript
>> Win32_DiskDrive WHERE InterfaceType='USB' not working ?
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
New Messages
No New Messages
Hot Topic w/ New Messages
Hot Topic w/o New Messages
Locked w/ New Messages
Locked w/o New Messages
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI