Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Win32_Logicaldisk - incomplete drive listing

129 views
Skip to first unread message

boomb...@yahoo.com

unread,
May 14, 2007, 3:33:06 PM5/14/07
to
Hello,

Recently I used the class Win32_Logicaldisk to list all mapped network
drives and found an issue.

For unknown reason some network drives are shown when I run NET USE,
but do not shown when I look for them via a Win32_Logicaldisk
collection.

Here is the output:

*****************************
C:\>net use
New connections will be remembered.


Status Local Remote Network

-------------------------------------------------------------------------------
Unavailable K: \\deimos\temp Microsoft Windows
Network
Disconnected R: \\sun\netlogon Microsoft Windows
Network
Disconnected Z: \\sun\c$ Microsoft Windows
Network
The command completed successfully.


C:\>cscript /nologo netdisk.vbs
Drive letter: R:
Drive letter: Z:

*****************************

Here is the netdisk.vbs, very simple, isn't it?

*****************************
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colDrives = objWMIService.ExecQuery("Select * From
Win32_LogicalDisk Where DriveType=4")
For Each objDrive in colDrives
Wscript.Echo "Drive letter: " & objDrive.DeviceID
Next
*****************************

Have anyone had this problem before?
Why it does not work?

Thak you for any ideas

\RemS

unread,
May 15, 2007, 5:11:00 AM5/15/07
to
"boomb...@yahoo.com" wrote:

In the VBS you filtered 'DriveType=4' <--- "is network".
Now, the drive that doesn't show up in vbs is in the output of 'net use '
marked as "Unavailable" --> when the provider is unresolvable the DriveType
stays Unknown .

to check this, modify the Set colDrives line in your script to;

Set colDrives = objWMIService.ExecQuery("Select * From "_
& "Win32_LogicalDisk Where DriveType=4 OR DriveType=0")

\RemS

boomb...@yahoo.com

unread,
May 15, 2007, 11:50:26 AM5/15/07
to

Thanks RemS

I tried your suggestion and removed the DriveType attribute from the
query.
So it is now very simple:

"Select * From Win32_LogicalDisk"


Here is the new output, as we see the letter K is not present either
but is still visible via NET USE.

Very strange ...

*************************************
C:\>cscript /nologo netdisk.vbs
Drive letter: A:
Drive letter: C:
Drive letter: D:


Drive letter: R:
Drive letter: Z:

*************************************


C:\>net use
New connections will be remembered.


Status Local Remote Network


---------------------------------------------------------------------------­----

\RemS

unread,
May 15, 2007, 6:03:01 PM5/15/07
to
"boomb...@yahoo.com" wrote:

- just being curious:
wat is the result if you query;


Set colDrives = objWMIService.ExecQuery("Select * From "_

& "Win32_LogicalDisk Where DriveType=0")

\RemS

boomb...@yahoo.com

unread,
May 15, 2007, 8:31:31 PM5/15/07
to
Ok. I tried.
It shows nothing.
=======================================

C:\>cscript /nologo netdisk.vbs

C:\>type netdisk.vbs

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Set colDrives = objWMIService.ExecQuery("Select * From

Win32_LogicalDisk Where DriveType=0")


For Each objDrive in colDrives

Wscript.Echo "Drive letter:" & objDrive.Name
Next


C:\>net use
New connections will be remembered.


Status Local Remote Network

-------------------------------------------------------------------------------


Unavailable K: \\deimos\temp Microsoft Windows
Network
Disconnected R: \\sun\netlogon Microsoft Windows
Network
Disconnected Z: \\sun\c$ Microsoft Windows
Network
The command completed successfully.

C:\>

===================================


Also I tried to use Win32_MappedLogicalDisk and Win32_DiskDrive
without any success.

That is creating some seriuos problems because I need a method to
enumerate all logical drives to find a free letter for a new drive.

Now, I am confused and have to search for a messy workaroud with
Registry keys...

Has anyone seen this behaviour?


\RemS

unread,
May 16, 2007, 6:10:01 AM5/16/07
to
OK,
thank you for trying. Good to know these things!

Tried the FileSystemObject also?


With CreateObject("Scripting.FileSystemObject")
For i = Asc("D") To Asc("Z")
If .DriveExists(Chr(i)) Then
wscript.echo "drive letter "& Chr(i) & ": is in use"
Else 'use this available driveletter to map a new drive
End If
Next
End With


\Rems


"boomb...@yahoo.com" wrote:

> Ok. I tried.
> It shows nothing.
> =======================================
>
> C:\>cscript /nologo netdisk.vbs
>
> C:\>type netdisk.vbs
>
> Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
> Set colDrives = objWMIService.ExecQuery("Select * From
> Win32_LogicalDisk Where DriveType=0")
> For Each objDrive in colDrives
> Wscript.Echo "Drive letter:" & objDrive.Name
> Next
>

\RemS

unread,
May 16, 2007, 6:28:03 AM5/16/07
to
"\RemS" wrote:

> OK,
> thank you for trying. Good to know these things!
>
> Tried the FileSystemObject also?
>

If this works (?), then input this line: Exit For
to end the loop after the *first* available drive letter is found.
(see example below)


With CreateObject("Scripting.FileSystemObject")
For i = Asc("D") To Asc("Z")
If .DriveExists(Chr(i)) Then
'wscript.echo "drive letter "& Chr(i) & ": is in use"
Else

firstAvailableDriveletter = Chr(i) & ":"
Exit For '(!)


End If
Next
End With

wscript.echo firstAvailableDriveletter

boomb...@yahoo.com

unread,
May 16, 2007, 9:15:23 PM5/16/07
to

I tried FileSystemObject and it seems to be affected as well.
However the phantom drive is still present in the NET USE output and
My Computer window.

===============================================
C:\>cscript disk.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

drive letter D: is in use
drive letter R: is in use
drive letter Z: is in use

boomb...@yahoo.com

unread,
May 16, 2007, 9:15:38 PM5/16/07
to

I tried FileSystemObject and it seems to be affected as well.
However the phantom drive is still present in the NET USE output and
My Computer window.

===============================================
C:\>cscript disk.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

drive letter D: is in use
drive letter R: is in use
drive letter Z: is in use

C:\>net use

0 new messages