Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

Need to Map drive with script


(!)

gfxrelay's Avatar
gfxrelay gfxrelay is offline
Member with 588 posts.
THREAD STARTER
 
Join Date: Oct 2005
Location: 127.0.0.1
Experience: A button!
24-Jan-2009, 04:46 PM #1
Need to Map drive with script
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?
TheOutcaste's Avatar
Computer Specs
Member with 9,028 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
25-Jan-2009, 12:36 AM #2
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.

Jerry
gfxrelay's Avatar
gfxrelay gfxrelay is offline
Member with 588 posts.
THREAD STARTER
 
Join Date: Oct 2005
Location: 127.0.0.1
Experience: A button!
25-Jan-2009, 05:56 AM #3
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
gfxrelay's Avatar
gfxrelay gfxrelay is offline
Member with 588 posts.
THREAD STARTER
 
Join Date: Oct 2005
Location: 127.0.0.1
Experience: A button!
25-Jan-2009, 05:59 AM #4
I managed to find a script that will more or less do what I want to do:

<HTML>
<HEAD>
<TITLE>S&G VPN Drive Map</title>
<HTA:APPLICATION
ApplicationName="MappingWithCredentials.HTA"
SingleInstance="Yes"
WindowsState="Normal"
Scroll="No"
Navigable="Yes"
MaximizeButton="No"
SysMenu="Yes"
Caption="Yes"
></HEAD>

<SCRIPT LANGUAGE="VBScript">

Sub Window_Onload
'# Size Window
sHorizontal = 440
sVertical = 175
Window.resizeTo sHorizontal, sVertical
'# Get Monitor Details
Set objWMIService = GetObject _
("winmgmts:root\cimv2")
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
Next
Set objWMIService = Nothing
'# Center window on the screen
intLeft = (intHorizontal - sHorizontal) /2
intTop = (intVertical - sVertical) /2
Window.moveTo intLeft, intTop
'# default window content
window.location.href="#Top"
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
Err.Clear
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
ELSE
Msgbox chr(34) & strPas & """ is an incorrect password !"
Exit Sub
End If
ELSE
Msgbox chr(34) & strUsr & """ is an incorrect Username !"
Exit Sub
End If

Set oShell = Nothing
Set objNetwork = Nothing
Self.Close()
End Sub


Sub CancelScript
Set oShell = Nothing
Set objNetwork = Nothing
Self.Close()
End Sub

</SCRIPT>


<BODY STYLE="font:14 pt arial; color:white; filterrogidXImageTransform.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">
<tr>
<td height="30">
<p align="right">Your Username</p>
</td>
<td height="30">&nbsp;&nbsp; <input type="text" name="UsrnameArea" size="30"></td></tr>
<tr>
<td height="30">
<p align="right">@domain.com Password</p>
</td>
<td height="30">&nbsp;&nbsp; <input type="password" name="PasswordArea" size="30"></td></tr>
</table><BR>
<HR color="#0000FF">
<Input id=runbutton class="button" type="button" value=" Create Drive " name="run_button" onClick="RunScript">
&nbsp;&nbsp;&nbsp;
<Input id=runbutton class="button" type="button" value="Cancel" name="cancel_button" onClick="CancelScript">
</CENTER>
</BODY>

</HTML>


Thanks for the help
TheOutcaste's Avatar
Computer Specs
Member with 9,028 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
25-Jan-2009, 10:58 PM #5
Your Welcome, though I didn't really help much. Thanks for posting the solution you found.

Jerry
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2