1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Need to Map drive with script

Discussion in 'Software Development' started by gfxrelay, Jan 24, 2009.

Thread Status:
Not open for further replies.
  1. gfxrelay

    gfxrelay Thread Starter

    Oct 26, 2005
    I have setup a network connection between two computers. I need a script that will prompt the user for their network credentials and them map seven network drives from the one computer to the the other. Does any one know how to create such a script?
  2. TheOutcaste


    Aug 7, 2007
    Why not just set the network shares to be mapped when the user logs on? Each user can have different shares mapped.

    Many questions if you need to use a script:

    1. Do you need specific drive letters to be used, or just the first available letter?
    2. Is there a chance that one of the shares may already be mapped?
      Do you want to use that mapping, even if on a different letter?
      Delete it and create a new one on correct letter?
    3. If the desired letter is in use (User created a persistent map for example), how would you want to handle that?
      Delete theirs (with or without a warning)?
      Re-map theirs to a different letter(with or without a warning)?
      Change your drive letter for your mapping?
    4. Is the Username for the network share the same as the Username they log into Windows with?
    5. Does the password have to be masked as they type it?
    You can use a batch file that will ask them for the password once. It will be visible as they type it.
    If you want the password masked, you can prompt them for the password for each share. The password will not be visible when they type it, but would have to be entered 7 times.
    You can use a vbscript to ask for the password once and mask it as they type.

    To use the vbscript you would need to change a security setting to allow local files to run a script, or they will get the "Blocked ActiveX" info bar, and have to "allow blocked content" each time.

  3. gfxrelay

    gfxrelay Thread Starter

    Oct 26, 2005
    Hi thanks for the reply. I am trying to map folders temporarily over a VPN so clients can only connect to certain folders. I am trying to set it up so that they can work on their files and disconnect the mapped folders when they close the VPN
  4. gfxrelay

    gfxrelay Thread Starter

    Oct 26, 2005
    I managed to find a script that will more or less do what I want to do:

    <TITLE>S&G VPN Drive Map</title>


    Sub Window_Onload
    '# Size Window
    sHorizontal = 440
    sVertical = 175
    Window.resizeTo sHorizontal, sVertical
    '# Get Monitor Details
    Set objWMIService = GetObject _
    intHorizontal = sHorizontal *2
    intVertical = sVertical *2
    Set colItems = objWMIService.ExecQuery( _
    "Select ScreenWidth, ScreenHeight from" _
    & " Win32_DesktopMonitor", , 48)
    For Each objItem In colItems
    sWidth= objItem.ScreenWidth
    sHeight = objItem.ScreenHeight
    If sWidth > sHorizontal _
    then intHorizontal = sWidth
    If sHeight > sVertical _
    then intVertical = sHeight
    Set objWMIService = Nothing
    '# Center window on the screen
    intLeft = (intHorizontal - sHorizontal) /2
    intTop = (intVertical - sVertical) /2
    Window.moveTo intLeft, intTop
    '# default window content
    End Sub

    Sub RunScript
    on Error Resume Next

    ' *** variables
    mDrive = "K:"
    strRemoteShare = "\\server\share"
    strDriveAlias = "share name"

    mDrive1 = "L:"
    strRemoteShare1 = "\\server\share"
    strDriveAlias1 = "share name"

    mDrive2 = "M:"
    strRemoteShare2 = "\\server\share"
    strDriveAlias2 = "share name"

    mDrive3 = "N:"
    strRemoteShare3 = "\\server\share"
    strDriveAlias3 = "share name"

    mDrive4 = "O:"
    strRemoteShare4 = "\\server\share"
    strDriveAlias4 = "share name"

    mDrive5 = "P:"
    strRemoteShare5 = "\\server\share"
    strDriveAlias5 = "share name"

    mDrive6 = "Q:"
    strRemoteShare6 = "\\server\share"
    strDriveAlias6 = "share name"

    strUPNsuffix = "@domain.com"

    minUSRnamelength = 2
    minPASSwrdlength = 3

    ' *** Map drive using the entered credentials

    strUsr = UsrnameArea.Value
    strPas = PasswordArea.Value

    Set objNetwork = CreateObject("WScript.Network")
    Set oShell = CreateObject("Shell.Application")

    If Len(strUsr) >= minUSRnamelength then
    strUsr = Ucase(strUsr) & strUPNsuffix '<--- adds the UPNsuffix to the account

    if Len(strPas) >= minPASSwrdlength then
    objNetwork.MapNetworkDrive mDrive, strRemoteShare, False, strUsr, strPas
    objNetwork.MapNetworkDrive mDrive1, strRemoteShare1, False, strUsr, strPas
    objNetwork.MapNetworkDrive mDrive2, strRemoteShare2, False, strUsr, strPas
    objNetwork.MapNetworkDrive mDrive3, strRemoteShare3, False, strUsr, strPas
    objNetwork.MapNetworkDrive mDrive4, strRemoteShare4, False, strUsr, strPas
    objNetwork.MapNetworkDrive mDrive5, strRemoteShare5, False, strUsr, strPas
    objNetwork.MapNetworkDrive mDrive6, strRemoteShare6, False, strUsr, strPas

    If Err.Number = 0 Then
    oShell.NameSpace(mDrive).Self.Name = strDriveAlias
    oShell.NameSpace(mDrive1).Self.Name = strDriveAlias1
    oShell.NameSpace(mDrive2).Self.Name = strDriveAlias2
    oShell.NameSpace(mDrive3).Self.Name = strDriveAlias3
    oShell.NameSpace(mDrive4).Self.Name = strDriveAlias4
    oShell.NameSpace(mDrive5).Self.Name = strDriveAlias5
    oShell.NameSpace(mDrive6).Self.Name = strDriveAlias6

    End If
    Msgbox chr(34) & strPas & """ is an incorrect password !"
    Exit Sub
    End If
    Msgbox chr(34) & strUsr & """ is an incorrect Username !"
    Exit Sub
    End If

    Set oShell = Nothing
    Set objNetwork = Nothing
    End Sub

    Sub CancelScript
    Set oShell = Nothing
    Set objNetwork = Nothing
    End Sub


    <BODY STYLE="font:14 pt arial; color:white; filter:progid:DXImageTransform.Microsoft.Gradient( GradientType=1, StartColorStr='#000000', EndColorStr='#0000FF')">
    <a name="Top"></a><CENTER>
    <table border="0" cellpadding="0" cellspacing="0"><font size="2" color="black" face="Arial">
    <td height="30">
    <p align="right">Your Username</p>
    <td height="30">&nbsp;&nbsp; <input type="text" name="UsrnameArea" size="30"></td></tr>
    <td height="30">
    <p align="right">@domain.com Password</p>
    <td height="30">&nbsp;&nbsp; <input type="password" name="PasswordArea" size="30"></td></tr>
    <HR color="#0000FF">
    <Input id=runbutton class="button" type="button" value=" Create Drive " name="run_button" onClick="RunScript">
    <Input id=runbutton class="button" type="button" value="Cancel" name="cancel_button" onClick="CancelScript">


    Thanks for the help:D
  5. TheOutcaste


    Aug 7, 2007
    Your Welcome, though I didn't really help much. Thanks for posting the solution you found.

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/794014