none
Display all network drives RRS feed

  • Question

  • How can I display all network drives? Do I have to do some VB scripting? Thanks.

    Status       Local     Remote                    Network
    -------------------------------------------------------------------------------
                 X:        \\windows\server\file1
                                                    Microsoft Windows Network
                 Y:        \\windows\server\file2
                                                    Microsoft Windows Network
    Unavailable  Z:        \\windows\server\file3
                                                    Microsoft Windows Network
    												
    I just want to display as:
    Network Drive
    X: \\windows\server\file1
    Y: \\windows\server\file2
    Z: \\windows\server\file3


    Saturday, February 22, 2020 7:51 PM

Answers

  • Exactly..

    Set WshNetwork = CreateObject("WScript.Network")
    Set oDrives = WshNetwork.EnumNetworkDrives

    For i = 0 to oDrives.Count - 1 Step 2
    Echo oDrives.Item(i) & " = " & oDrives.Item(i+1)
    Next

    Save the above as MappedDrive.vbs and create a custom field..

    HTH
    -mario

    • Proposed as answer by mariora_ Sunday, February 23, 2020 3:02 PM
    • Marked as answer by slick.user Monday, February 24, 2020 8:00 AM
    Sunday, February 23, 2020 3:01 PM

All replies

  • Exactly..

    Set WshNetwork = CreateObject("WScript.Network")
    Set oDrives = WshNetwork.EnumNetworkDrives

    For i = 0 to oDrives.Count - 1 Step 2
    Echo oDrives.Item(i) & " = " & oDrives.Item(i+1)
    Next

    Save the above as MappedDrive.vbs and create a custom field..

    HTH
    -mario

    • Proposed as answer by mariora_ Sunday, February 23, 2020 3:02 PM
    • Marked as answer by slick.user Monday, February 24, 2020 8:00 AM
    Sunday, February 23, 2020 3:01 PM
  • Mario,

    I'm getting error when using Echo alone.

    So I added below but got this error when using custom in BGinfo.

    If I run the VB Script, I can get the echo w/o any issue.

    Set WshNetwork = CreateObject("WScript.Network")
    Set oDrives = WshNetwork.EnumNetworkDrives

    For i = 0 to oDrives.Count - 1 Step 2
    WScript.Echo oDrives.Item(i) & " = " & oDrives.Item(i+1)
    Next

    Microsoft VBScript runtime error Line 5, position 1 Object required: WScript


    Sunday, February 23, 2020 8:35 PM
  • yep, you have to remove any reference to WSCRIPT..

    Infact BGINFO uses under the cover the srcobj.dll and all the other script dlls needed without refereing to the engine wscript or cscript..

    So, when you test the script in cscript or wscript you can use all the reference to Wscript, but when saving the script for use in bginfo you have to remove those reference..

    For this reason I removed them from what i wrote.. you added it back and now get the error.. :-)

    Remove it from the echo command.. instead of wscript.echo just Echo...

    HTH

    -mario

    Monday, February 24, 2020 7:30 AM
  • Thanks and got it!
    Monday, February 24, 2020 8:00 AM