Windows Vista Forums

Map network drive if permission is granted.

  1. #1


    hb21l5 Guest

    Map network drive if permission is granted.

    I have this script which works fine,
    only problem is, it maps the drive whether they have permission or not. and
    so creating lots of mapped drives (accessable / unaccessable) on their
    explorers.

    Is there a way to check access before mapping the drive?

    e.g.
    if permission granted, then
    map drive
    end if



    cheers Dave


    Set WshNetwork = CreateObject("WScript.Network")
    Set oDrives = WshNetwork.EnumNetworkDrives
    dim drivePath, driveLetter
    on error resume next
    'parse parameters
    driveLetter = Wscript.arguments(0) & ":"
    drivePath = Wscript.arguments(1)
    'set drive found flag
    foundDrive = false

    'check to see if the drive map matches, if not then over write with the new
    one
    For i = 0 to oDrives.Count - 1 Step 2

    'checks to see if the drive letter exists
    if oDrives.Item(i) = driveLetter then
    foundDrive = true
    if oDrives.Item(i+1) <> drivePath then
    'if the map don't match then change the mapping
    wshNetwork.RemoveNetworkDrive driveLetter, true, true
    WshNetwork.MapNetworkDrive driveLetter, drivePath, false
    end if
    end if
    Next

    'map drive if corresponding drive letter wasn't found
    if foundDrive = false then
    WshNetwork.MapNetworkDrive driveLetter, drivePath
    end if
    'Clean up
    Set oDrives = Nothing
    set WshNetwork = nothing

      My System SpecsSystem Spec

  2. #2


    James Whitlow Guest

    Re: Map network drive if permission is granted.

    "hb21l5" <hb21l5@xxxxxx> wrote in message
    news59D792E-E61E-440B-B138-269DA4F771FA@xxxxxx

    >I have this script which works fine,
    > only problem is, it maps the drive whether they have permission or not.
    > and
    > so creating lots of mapped drives (accessable / unaccessable) on their
    > explorers.
    >
    > Is there a way to check access before mapping the drive?
    >
    > e.g.
    > if permission granted, then
    > map drive
    > end if
    Use the 'FolderExists' method of 'Scripting.FileSystemObject'. If the
    user has permissions to the share, it will return 'True'. Otherwise, it will
    return 'False'.

    If oFSO.FolderExists("\\server\share") then
    'Map Drive code
    End If



      My System SpecsSystem Spec

Map network drive if permission is granted.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard Drive Permission Errors doublefunk General Discussion 5 12 Apr 2010
Re: Permissions to Security Center may not be granted to client comput Cliff Galiher SBS Server 0 09 Nov 2009
Do not have permission on networked drive Neal Vista networking & sharing 1 17 Aug 2008
File permission on 2nd hard drive Benjamin M Vista security 1 05 Feb 2007
Trust Not Granted error in WPF web application. yauhen.safrankou@gmail.com Avalon 0 14 Jul 2006