Announcement

Collapse
No announcement yet.

VB Script for Mapping Network Folders

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB Script for Mapping Network Folders

    I'm running a Win2008 domain, and have a User-based GPO referencing a VB
    script which shares several network folders, each shared from a single file
    server. This GPO applies to "Domain Users." What's odd is that I get an error
    when logging into the file server itself as Administrator. Here is the script
    and the error:

    Script:

    ' VBScript logon script program.
    Option Explicit
    Dim objNetwork

    Set objNetwork = CreateObject("Wscript.Network")

    ' Trap error if R: already in use.
    On Error Resume Next
    objNetwork.MapNetworkDrive "R:", "\\SQL1\marketing"
    If (Err.Number <> 0) Then
    ' Restore normal error handling.
    On Error GoTo 0
    ' Attempt to remove drive mapping.
    objNetwork.RemoveNetworkDrive "R:", True, True
    ' Try again to map the drive.
    objNetwork.MapNetworkDrive "R:", "\\SQL1\marketing"
    End If
    ' Restore normal error handling.
    On Error GoTo 0

    Error:

    Script: \\domain.local\...\share.vbs
    Line: 14
    Char: 5
    Error: This network connection does not exist
    Code: 800708CA
    Source: WSHNetwork.RemoveNetworkDrive

    Thoughts?

  • #2
    Re: VB Script for Mapping Network Folders

    Instead of triggering an error why not just do this?

    Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objNetwork = CreateObject("Wscript.Network") 
    If (objFSO.DriveExists("R:") = True) Then 
        objNetwork.RemoveNetworkDrive "R:", True, True 
    End If 
    objNetwork.MapNetworkDrive "R:", "\\SQL1\marketing"
    I tested on my system and it works fine. The error you are getting is normal if the system cannot find the folder to remove (IE: It is already gone).

    Hobie

    Comment

    Working...
    X