1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
| <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
' Declare global variable outside the Subs
Dim intMinutes
Dim intSeconds
Dim strTimerStart
Sub Window_onLoad
strDrive = "\\server\share\"
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
intMinutes = 30
intSeconds = 0
strTimerStart = intMinutes & ":" & Right("0" & intSeconds, 2)
span_clock.InnerHTML = strTimerStart
iTimerID = window.setInterval("DisconnectDrive_Timer", 1000)
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 "H:", 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
Sub DisconnectDrive
Set objNetwork = CreateObject("Wscript.Network")
'Set colDrives = objNetwork.EnumNetworkDrives
'strDrives = "You have the following drives mapped:"
'For intDrive = 0 To UBound(colDrives) - 1 Step 2
' strDrives = strDrives & VbCrLf & colDrives(intDrive) & " " & colDrives(intDrive + 1)
'Next
'strToDisconnect = InputBox(strDrives, "Disconnect Network Drive")
'objNetwork.RemoveNetworkDrive strToDisconnect, True
strToDisconnect = "H:"
On Error Resume Next
----> objNetwork.RemoveNetworkDrive strToDisconnect, True, True
If Err.Number = 0 Then
On Error GoTo 0
MsgBox "Drive has been disconnected."
Else
Err.Clear
On Error GoTo 0
MsgBox "Failed to disconnect " & strToDisconnect
End If
End Sub
Sub DisconnectDrive_Timer
If intSeconds = 0 Then
If intMinutes = 0 Then
Call DisconnectDrive
span_clock.InnerHTML = strTimerStart
Else
intMinutes = intMinutes - 1
End If
intSeconds = 59
Else
intSeconds = intSeconds - 1
End If
span_clock.innerHTML = intMinutes & ":" & Right("00" & intSeconds, 2)
End Sub
Sub ResetForm
txt_username.Value = ""
txt_password.Value = ""
txt_drivepath.Value = "\\server\share\"
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="Reset" name="btn_resetform" onClick="vbs:ResetForm">     
<input type="button" value="Disconnect Network Drive" name="btn_disconnectdrive" onClick="vbs:DisconnectDrive">     
<input type="button" value="Map Drive" name="btn_mapdrive" onClick="vbs:MapDrive">     
<input type="button" value="Exit" name="btn_exit" onClick="vbs:window.close"><br><br>
</td>
</tr>
<tr>
<td align='center'>
Drive will be disconnected in
<span id="span_clock">
</span>
 minute(s)
</td>
</tr>
</table>
</body> |
Partager