Modify Script

Batch, ASP, JScript, Kixtart, etc.
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.
This topic is 13 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
araman
Posts: 5
Last visit: Wed May 05, 2010 12:15 am

Modify Script

Post by araman »

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>
User avatar
araman
Posts: 5
Last visit: Wed May 05, 2010 12:15 am

Modify Script

Post by araman »

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>
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Modify Script

Post by jvierra »

Just enter the share name into the text box as teh script requests.
User avatar
araman
Posts: 5
Last visit: Wed May 05, 2010 12:15 am

Modify Script

Post by araman »

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
User avatar
araman
Posts: 5
Last visit: Wed May 05, 2010 12:15 am

Modify Script

Post by araman »

if you are refering to line 48 it still maps to the home directory
User avatar
araman
Posts: 5
Last visit: Wed May 05, 2010 12:15 am

Modify Script

Post by araman »

txt_drivepath.Value = strDrive & txt_username.Value


I dont want the txt_username.value
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Modify Script

Post by rasimmer »

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
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Modify Script

Post by rasimmer »

No sense of adventure JVierra... ;oP
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Modify Script

Post by jvierra »

ras- no idea what teh poster is trying to accomplish or why. Just don't want to see someone waste days trying to re-invent the wheel only to find it won't be round.

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Modify Script

Post by jvierra »

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.


This topic is 13 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked