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
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
-------------------------------------------------------------------------------
- just being curious:
wat is the result if you query;
Set colDrives = objWMIService.ExecQuery("Select * From "_
& "Win32_LogicalDisk Where DriveType=0")
\RemS
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?
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
>
> 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
===============================================
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:\>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