Hello,

I need to find a corresponding drive letter of a usb stick.
My script using Win32_LogicalDisk works fine.
Exept it accesses on some computers the Floppy drive which makes the
script to become unreliable/unstable. Is there a way to get passed the
accessing of floppy drive ?

Knowing that usb sticks are removable drives ! I'm running xp but not
under admin rights.

That is important because I'm trying to implement a solution that
works on all machine (with and whitout admin rights!!)

Can you help me out ?

In advance thanks and kind regards

Re: Win32_LogicalDisk and usb sticks without accessing floppy ? by Dominic

Dominic
Mon Jul 30 10:39:25 CDT 2007

I'm guessing that you have a SELECT statement that is something like
("SELECT * from Win32_LogicalDisk") - selecting all of the logical
disks on the system.

You may be able to use a combination of DriveType and MediaType
properties to exclude the floppy disk drive.

For example,

("SELECT * from Win32_LogicalDisk WHERE MediaType = 11")

or

("SELECT * from Win32_LogicalDisk WHERE DriveType = 3")

I don't have a system with a floppy disk drive available on so I
haven't tested this.

Dominic



Re: Win32_LogicalDisk and usb sticks without accessing floppy ? by Matthias

Matthias
Mon Jul 30 11:42:29 CDT 2007

Dominic Johnson wrote:
> I'm guessing that you have a SELECT statement that is something like
> ("SELECT * from Win32_LogicalDisk") - selecting all of the logical
> disks on the system.
>
> You may be able to use a combination of DriveType and MediaType
> properties to exclude the floppy disk drive.
>
> For example,
>
> ("SELECT * from Win32_LogicalDisk WHERE MediaType = 11")
>
> or
>
> ("SELECT * from Win32_LogicalDisk WHERE DriveType = 3")
>
> I don't have a system with a floppy disk drive available on so I
> haven't tested this.
>
It's not that easy.

While you can have a combined where clause

("SELECT * from Win32_LogicalDisk WHERE DriveType = 2 AND MediaType = 11")
See also :
<http://msdn2.microsoft.com/en-us/library/aa394054.aspx>
<http://msdn2.microsoft.com/en-us/library/aa394605.aspx>

DriveType hasn't to be 2 with every USB Stick and
MediaType may be 0 11 or 12 or more worse NULL.

Other MediaTypes between 0 and ~25 are all different floppy formattings.
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/Win32_LogicalDisk.asp>
The select forces an access to the flopy drive to detect the media - what
may cause OPs problem.

I'm still juggling with different sticks to find a way

--
Greetings
Matthias

Re: Win32_LogicalDisk and usb sticks without accessing floppy ? by chapeau_melon

chapeau_melon
Mon Jul 30 11:50:51 CDT 2007

thanks for the replies, but it is indead not that easy.

Here is some code I tried but without succes since logicaldisk is
allways searching all the drives on the computer.

Maybe this can help you further. playing with the drivetypes has no
use in my case since my usb and floppy are both 2.

Regards

strComputer = "."
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")
Set colDiskDrives = objWMI.ExecQuery _
("Select * from Win32_DiskDrive WHERE InterfaceType='USB'")

For Each objDiskDrive In colDiskDrives
strDeviceID = objDiskDrive.Caption
wscript.echo strdeviceID

Set colDisks = objWMI.ExecQuery ("Select Name from Win32_LogicalDisk
Where DriveType=2 And VolumeName='MERLIN'")
For each objDisk in colDisks
Merlindr = objDisk.Name
wscript.echo Merlindr
next

Next


Re: Win32_LogicalDisk and usb sticks without accessing floppy ? by chapeau_melon

chapeau_melon
Mon Jul 30 12:48:50 CDT 2007

Can someone try this. I have no floppy.

You need to insert a usb stick (named Merlin)

Is there any access you can hear on the floppy drive ? even for a
slight second ?

regards,


strComputer = "."
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

Set colDisks = objWMI.ExecQuery ("Select Name from Win32_LogicalDisk
Where DriveType=2 And VolumeName='MERLIN' and DeviceID > 'A:'")
For each objDisk in colDisks
Merlindr = objDisk.Name
wscript.echo Merlindr
next


Re: Win32_LogicalDisk and usb sticks without accessing floppy ? by urkec

urkec
Tue Jul 31 03:14:20 CDT 2007

Yes, there is, but if I leave out VolumeName='MERLIN' there's no attempt to
acces the floppy:

strComputer = "."
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

Set colDisks = objWMI.ExecQuery ("Select Name from Win32_LogicalDisk Where
DriveType=2 and DeviceID <> 'A:'")

For each objDisk in colDisks
Merlindr = objDisk.Name
wscript.echo Merlindr
next

Also no sound when I try this:

strComputer = "."
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

Set colDisks = objWMI.ExecQuery ("Select Name from Win32_LogicalDisk Where
Not Description Like '%Floppy%'")
For each objDisk in colDisks
Merlindr = objDisk.Name
wscript.echo Merlindr
next

--
urkec


"chapeau_melon" wrote:

> Can someone try this. I have no floppy.
>
> You need to insert a usb stick (named Merlin)
>
> Is there any access you can hear on the floppy drive ? even for a
> slight second ?
>
> regards,
>
>
> strComputer = "."
> Set objWMI = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer _
> & "\root\cimv2")
>
> Set colDisks = objWMI.ExecQuery ("Select Name from Win32_LogicalDisk
> Where DriveType=2 And VolumeName='MERLIN' and DeviceID > 'A:'")
> For each objDisk in colDisks
> Merlindr = objDisk.Name
> wscript.echo Merlindr
> next
>
>

Re: Win32_LogicalDisk and usb sticks without accessing floppy ? by Matthias

Matthias
Tue Jul 31 04:18:16 CDT 2007

urkec wrote:
> Yes, there is, but if I leave out VolumeName='MERLIN' there's no attempt to
> acces the floppy:
>

("Select Name from Win32_LogicalDisk Where DriveType=2 and DeviceID <> 'A:'")
("Select Name from Win32_LogicalDisk Where Not Description Like '%Floppy%'")

I'm sorry to say there _IS_ an access to the floppy drive with both select's

They also have other disadvantages, I assigned some of my usb sticks
drive A:/B: via diskmgmt.msc (on a notebook without floppy drive).

And the description is localized, so you have to use a proper key for the
like clause.

With diskmgmt.msc you may also assign a folder on a ntfs drive instead of a
drive letter, so 'i feel a really universal solution has to take a
different approach.

--
Greetings
Matthias

Re: Win32_LogicalDisk and usb sticks without accessing floppy ? by chapeau_melon

chapeau_melon
Tue Jul 31 04:44:42 CDT 2007

thanks for the replies.

<<They also have other disadvantages, I assigned some of my usb
sticks
drive A:/B: via diskmgmt.msc (on a notebook without floppy drive).>>

I see no problem in this, cause this situation will most probably
never happen in my working enviroment.