I would like to modify this script so that it maps to the share,10.92.36.249data , instead of the users home directory. Thanks for any help
Expand|Select|Wrap|Line Numbers
</head>
<title>Map Network Drive</title>
<HTA:APPLICATION
APPLICATIONNAME="Map Drive"
BORDER="thin"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<script language="VBScript">
Dim strDrive
Sub Window_onLoad
strDrive = "10.92.36.249data"
If Right(strDrive, 1) <> "" Then strDrive = strDrive & ""
intWidth = 800
intHeight = 600
Me.ResizeTo intWidth, intHeight
Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
txt_drivepath.Value = strDrive
End Sub
Sub Default_Buttons
If Window.Event.KeyCode = 13 Then
btn_mapdrive.Click
End If
End Sub
Sub Update_Path
txt_drivepath.Value = strDrive & txt_username.Value
End Sub
Sub MapDrive
If Trim(txt_username.Value) = "" Then
MsgBox "Please enter a username."
txt_username.Focus
ElseIf Trim(txt_password.Value) = "" Then
MsgBox "Please enter a password."
txt_password.Focus
Else
Set objNetwork = CreateObject("WScript.Network")
uName = txt_username.Value
pWord = txt_password.Value
homeDrive = txt_drivepath.value
On Error Resume Next
objNetwork.MapNetworkDrive "J:", homeDrive, True, uName, pWord
If Err.Number = 0 Then
Err.Clear
On Error GoTo 0
MsgBox "Drive mapping complete."
Else
Err.Clear
On Error GoTo 0
MsgBox "Failed to map network drive."
End If
End If
End Sub
</script>
<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
<table width='90%' height = '100%' align='center' border='0'>
<tr>
<td align='center'>
<h2>Map a Drive</h2>
</td>
</tr>
<tr>
<td>
User Name:<br>
<input type="text" maxlength="30" size="40" id="txt_username" name="txt_username" onchange="vbs:Update_Path"><br><br>
</td>
</tr>
<tr>
<td>
Pasword:<br>
<input type="password" maxlength="30" size="40" id="txt_password" name="txt_password"><br><br>
</td>
</tr>
<tr>
<td>
Drive Path:<br>
<input type="text" maxlength="30" size="40" id="txt_drivepath" name="txt_drivepath" readonly><br><br>
</td>
</tr>
<tr>
<td align='center'>
<input type="button" value="Map Drive" name="btn_mapdrive" onClick="vbs:MapDrive"><br><br>
</td>
</tr>
</table>
</body>
Modify Script
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Modify Script
I would like to modify this script so that it maps to the share,10.92.36.249data , instead of the users home directory. Thanks for any help
Expand|Select|Wrap|Line Numbers
</head>
<title>Map Network Drive</title>
<HTA:APPLICATION
APPLICATIONNAME="Map Drive"
BORDER="thin"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<script language="VBScript">
Dim strDrive
Sub Window_onLoad
strDrive = "10.92.36.249data"
If Right(strDrive, 1) <> "" Then strDrive = strDrive & ""
intWidth = 800
intHeight = 600
Me.ResizeTo intWidth, intHeight
Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
txt_drivepath.Value = strDrive
End Sub
Sub Default_Buttons
If Window.Event.KeyCode = 13 Then
btn_mapdrive.Click
End If
End Sub
Sub Update_Path
txt_drivepath.Value = strDrive & txt_username.Value
End Sub
Sub MapDrive
If Trim(txt_username.Value) = "" Then
MsgBox "Please enter a username."
txt_username.Focus
ElseIf Trim(txt_password.Value) = "" Then
MsgBox "Please enter a password."
txt_password.Focus
Else
Set objNetwork = CreateObject("WScript.Network")
uName = txt_username.Value
pWord = txt_password.Value
homeDrive = txt_drivepath.value
On Error Resume Next
objNetwork.MapNetworkDrive "J:", homeDrive, True, uName, pWord
If Err.Number = 0 Then
Err.Clear
On Error GoTo 0
MsgBox "Drive mapping complete."
Else
Err.Clear
On Error GoTo 0
MsgBox "Failed to map network drive."
End If
End If
End Sub
</script>
<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
<table width='90%' height = '100%' align='center' border='0'>
<tr>
<td align='center'>
<h2>Map a Drive</h2>
</td>
</tr>
<tr>
<td>
User Name:<br>
<input type="text" maxlength="30" size="40" id="txt_username" name="txt_username" onchange="vbs:Update_Path"><br><br>
</td>
</tr>
<tr>
<td>
Pasword:<br>
<input type="password" maxlength="30" size="40" id="txt_password" name="txt_password"><br><br>
</td>
</tr>
<tr>
<td>
Drive Path:<br>
<input type="text" maxlength="30" size="40" id="txt_drivepath" name="txt_drivepath" readonly><br><br>
</td>
</tr>
<tr>
<td align='center'>
<input type="button" value="Map Drive" name="btn_mapdrive" onClick="vbs:MapDrive"><br><br>
</td>
</tr>
</table>
</body>
Expand|Select|Wrap|Line Numbers
</head>
<title>Map Network Drive</title>
<HTA:APPLICATION
APPLICATIONNAME="Map Drive"
BORDER="thin"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<script language="VBScript">
Dim strDrive
Sub Window_onLoad
strDrive = "10.92.36.249data"
If Right(strDrive, 1) <> "" Then strDrive = strDrive & ""
intWidth = 800
intHeight = 600
Me.ResizeTo intWidth, intHeight
Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
txt_drivepath.Value = strDrive
End Sub
Sub Default_Buttons
If Window.Event.KeyCode = 13 Then
btn_mapdrive.Click
End If
End Sub
Sub Update_Path
txt_drivepath.Value = strDrive & txt_username.Value
End Sub
Sub MapDrive
If Trim(txt_username.Value) = "" Then
MsgBox "Please enter a username."
txt_username.Focus
ElseIf Trim(txt_password.Value) = "" Then
MsgBox "Please enter a password."
txt_password.Focus
Else
Set objNetwork = CreateObject("WScript.Network")
uName = txt_username.Value
pWord = txt_password.Value
homeDrive = txt_drivepath.value
On Error Resume Next
objNetwork.MapNetworkDrive "J:", homeDrive, True, uName, pWord
If Err.Number = 0 Then
Err.Clear
On Error GoTo 0
MsgBox "Drive mapping complete."
Else
Err.Clear
On Error GoTo 0
MsgBox "Failed to map network drive."
End If
End If
End Sub
</script>
<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
<table width='90%' height = '100%' align='center' border='0'>
<tr>
<td align='center'>
<h2>Map a Drive</h2>
</td>
</tr>
<tr>
<td>
User Name:<br>
<input type="text" maxlength="30" size="40" id="txt_username" name="txt_username" onchange="vbs:Update_Path"><br><br>
</td>
</tr>
<tr>
<td>
Pasword:<br>
<input type="password" maxlength="30" size="40" id="txt_password" name="txt_password"><br><br>
</td>
</tr>
<tr>
<td>
Drive Path:<br>
<input type="text" maxlength="30" size="40" id="txt_drivepath" name="txt_drivepath" readonly><br><br>
</td>
</tr>
<tr>
<td align='center'>
<input type="button" value="Map Drive" name="btn_mapdrive" onClick="vbs:MapDrive"><br><br>
</td>
</tr>
</table>
</body>
Modify Script
it doesnt allow you to enter the share name it inserts the username at the end of the share 10.92.36.249data for the home directory. I want to remove that and just have it map to the share after login
The ip will never change
The ip will never change
Modify Script
txt_drivepath.Value = strDrive & txt_username.Value
I dont want the txt_username.value
I dont want the txt_username.value
Modify Script
Alright, try this, in the Windows_Onload sub, make this modification:
txt_drivepath.Value = strDrive
txt_drivepath.Disabled = True
Then, add the following sub:
Sub txt_username_onKeyUp()
txt_DrivePath = strDrive & txt_username.Value
End Sub
Each time a key is pressed and then released (i.e. typing a letter), it will update the drive field with what was typed. Then, when you call this:
homeDrive = txt_drivepath.value
it will have the data from txt_Username. If you think that someone will possibly paste something in there, then you may need to add another event like _onBlur which is someone has clicked in the field and then click on something else (like the submit button) which removes focus from that field. You would just copy the sub I posted above and change onKeyUp to onBlur and have both subs in your vbScript body.rasimmer2010-05-05 07:36:55
txt_drivepath.Value = strDrive
txt_drivepath.Disabled = True
Then, add the following sub:
Sub txt_username_onKeyUp()
txt_DrivePath = strDrive & txt_username.Value
End Sub
Each time a key is pressed and then released (i.e. typing a letter), it will update the drive field with what was typed. Then, when you call this:
homeDrive = txt_drivepath.value
it will have the data from txt_Username. If you think that someone will possibly paste something in there, then you may need to add another event like _onBlur which is someone has clicked in the field and then click on something else (like the submit button) which removes focus from that field. You would just copy the sub I posted above and change onKeyUp to onBlur and have both subs in your vbScript body.rasimmer2010-05-05 07:36:55
Modify Script
ras - the poster said he does NOT want teh user name.
U think this is just someone who is experimenting with script and found a slightly broken script on the web.
Mapping to an IP will not always work. It can create some issues. Most admins know this so I don't think the poster is an admin but I could be wrong.
Over the years there have been numerous attempts to use an HTA for logon. Most corporations have abandoned these attempts. I know I had many little battles to try and head off this practice. Loasing teh HTML susystem along with the scripting system can expose many weeknesses in teh Windows logon process. It can also slow things down considereable on pre-XP SP2 machines and will wreck havoc on a terminal server if certain things go wrong. I am not saying it can never be used but that it should only be used if absolutely necessary. I prefer writing a custom logn application to habdle any required user input. Just set the application to run in the startup group. YOu can even place the HTA in the startup group or on the desktop and avoind issues.
The most intersting question about using an HTA t map a dtive came from a junior hacker who could not be convinced that he could NOT map a drive to a web server. He thought that an HTA had some magical ability map drive to web sites because it was a form of browser. No amount of explanation would convince him that what he was trying to do was impossible.
I like HTAs for many types of data collection when we need something to be built in 10 minutes. When the requirement is larger I always use Windows FOrms either with Acces,VB or VB.NET to quickly cobble up a form. If you keep the requirement free of any processing - just daya gathering - this is quick, easy and very reliable. Microsft now gives away VBExpress which is perfect for this task.
U think this is just someone who is experimenting with script and found a slightly broken script on the web.
Mapping to an IP will not always work. It can create some issues. Most admins know this so I don't think the poster is an admin but I could be wrong.
Over the years there have been numerous attempts to use an HTA for logon. Most corporations have abandoned these attempts. I know I had many little battles to try and head off this practice. Loasing teh HTML susystem along with the scripting system can expose many weeknesses in teh Windows logon process. It can also slow things down considereable on pre-XP SP2 machines and will wreck havoc on a terminal server if certain things go wrong. I am not saying it can never be used but that it should only be used if absolutely necessary. I prefer writing a custom logn application to habdle any required user input. Just set the application to run in the startup group. YOu can even place the HTA in the startup group or on the desktop and avoind issues.
The most intersting question about using an HTA t map a dtive came from a junior hacker who could not be convinced that he could NOT map a drive to a web server. He thought that an HTA had some magical ability map drive to web sites because it was a form of browser. No amount of explanation would convince him that what he was trying to do was impossible.
I like HTAs for many types of data collection when we need something to be built in 10 minutes. When the requirement is larger I always use Windows FOrms either with Acces,VB or VB.NET to quickly cobble up a form. If you keep the requirement free of any processing - just daya gathering - this is quick, easy and very reliable. Microsft now gives away VBExpress which is perfect for this task.