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

RE: Win32_Logicaldisk - incomplete drive listing by RemS

RemS
Tue May 15 04:11:00 CDT 2007

"boomboom999@yahoo.com" wrote:

> 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
>

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

Re: Win32_Logicaldisk - incomplete drive listing by boomboom999

boomboom999
Tue May 15 10:50:26 CDT 2007


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


---------------------------------------------------------------------------=
=AD----
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.







Re: Win32_Logicaldisk - incomplete drive listing by RemS

RemS
Tue May 15 17:03:01 CDT 2007

"boomboom999@yahoo.com" wrote:

>
> 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
>
>
> ---------------------------------------------------------------------------­----
> 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.
>

- just being curious:
wat is the result if you query;
Set colDrives = objWMIService.ExecQuery("Select * From "_
& "Win32_LogicalDisk Where DriveType=0")

\RemS

Re: Win32_Logicaldisk - incomplete drive listing by boomboom999

boomboom999
Tue May 15 19:31:31 CDT 2007

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?



Re: Win32_Logicaldisk - incomplete drive listing by RemS

RemS
Wed May 16 05:10:01 CDT 2007

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


"boomboom999@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
>
> 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?


Re: Win32_Logicaldisk - incomplete drive listing by RemS

RemS
Wed May 16 05:28:03 CDT 2007

"\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




Re: Win32_Logicaldisk - incomplete drive listing by boomboom999

boomboom999
Wed May 16 20:15:23 CDT 2007


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
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.


Re: Win32_Logicaldisk - incomplete drive listing by boomboom999

boomboom999
Wed May 16 20:15:38 CDT 2007


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
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.