Code:
@echo off
::-----------------------------------------Selectuser----------------------------------------
:selectuser
CLS
@COLOR 17
ECHO *************MAPPING SHARED DRIVES*************
ECHO ...............................................
ECHO put your domain username
ECHO Example..
ECHO firstname.lastname
ECHO Do not include a domain (@example.com, example\)
ECHO ...............................................
ECHO.
SET /P user=Type in your domain username, then press ENTER:
net use /delete S:
net use /delete U:
net use /delete P:
net use S: \\servername.example.com\share /user:domain\%user% /persistent:yes
net use U: \\servername.example.com\Users\%user% /user:domain\%user% /persistent:yes
net use P: \\servername.example.com\Public /user:domain\%user% /persistent:yes
Code:
<HTML>
<head><title>Drive Mapper</Title>
<HTA:APPLICATION
APPLICATIONNAME="Drive Mapper"
ICON="/path/to/file.ico"
SCROLL="auto"
SINGLEINSTANCE="yes"
NAVIGABLE="yes"/>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes">
</Head>
<Script Language="VBSCRIPT" Type = "text/vbscript">
Sub Window_Onload
Window.resizeTo 600,480
call ShowDrives
call AreYouConnected
End Sub
Sub CloseWindow
self.close
End Sub
Sub Reload
Location.Reload(True)
End Sub
Sub AreYouConnected
blnAnswer = window.confirm("If you are connected to the network or VPN, please click OK. If you do not want to connect to your share drives at this time, just hit cancel. If you are working remotely, you can launch your VPN client before clicking OK.")
If blnAnswer Then
Else
CloseWindow
End If
End Sub
FUNCTION ShowDrives
DispDrives.value = ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
If objDrive.IsReady = True Then
DispDrives.value = DispDrives.value & vbcrlf & objDrive.path & " " & objDrive.sharename
End If
Next
END FUNCTION
FUNCTION MapPDrive
On Error Resume Next
Set objNet = CreateObject("Wscript.Network")
objNet.RemoveNetworkDrive "P:"
objNet.MapNetworkDrive "P:", "\\server.example.com\public", True
call ShowDrives
END FUNCTION
FUNCTION MapSDrive
On Error Resume Next
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", OPTIONS, "\\server.example.com")
If objFolder Is Nothing Then
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
Set objNet = CreateObject("Wscript.Network")
objNet.RemoveNetworkDrive "S:"
objNet.MapNetworkDrive "S:", objPath, True
call ShowDrives
END FUNCTION
FUNCTION MapUDrive
On Error Resume Next
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", OPTIONS, "\\server.example.com\users")
If objFolder Is Nothing Then
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
Set objNet = CreateObject("Wscript.Network")
objNet.RemoveNetworkDrive "U:"
objNet.MapNetworkDrive "U:", objPath, True
call ShowDrives
END FUNCTION
FUNCTION DisconnectDrives
On Error Resume Next
blnAnswer = window.confirm("Are you sure you want to disconnect all network mapped drives?")
If blnAnswer Then
DIM objNetwork,colDrives,i
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
' Force Removal of network drive and remove from user profile
' objNetwork.RemoveNetworkDrive strName, [bForce], [bUpdateProfile]
objNetwork.RemoveNetworkDrive colDrives.Item(i),TRUE,TRUE
Next
call ShowDrives
Else
End If
END FUNCTION
intButtonCount = 1
Sub AddDriveLetter
Set OFS = CreateObject("Scripting.FileSystemObject")
For x = 65 To 90
Select Case Chr(x)
Case "A", "B", "C", "D", "P", "S", "U"
Case Else
If oFS.DriveExists(Chr(x)) = False Then
MapLtr = Chr(x)
End If
End Select
If IsEmpty(MapLtr) = False Then
Exit For
End If
Next
strHTML = DataArea.InnerHTML
strHTML = strHTML & "<input id=" & intButtonCount & " type=" & Chr(34) & "button" & Chr(34) & _
" value= " & Chr(34) & "Map Drive " & MapLtr & Chr(34) &" onClick=" & Chr(34) & _
"NextDriveSubRoutine" & Chr(34) & ">"
DataArea.InnerHTML = strHTML
intButtonCount = intButtonCount + 1
End Sub
Sub NextDriveSubRoutine
Set objButton = window.event.srcelement
strID = objButton.id
On Error Resume Next
Set OFS = CreateObject("Scripting.FileSystemObject")
For x = 65 To 90
Select Case Chr(x)
Case "A", "B", "C", "D", "P", "S", "U"
Case Else
If oFS.DriveExists(Chr(x)) = False Then
MapLtr = Chr(x)
End If
End Select
If IsEmpty(MapLtr) = False Then
Exit For
End If
Next
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", OPTIONS, "\\server.example.com")
If objFolder Is Nothing Then
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
Set objNet = CreateObject("Wscript.Network")
objNet.RemoveNetworkDrive MapLtr
objNet.MapNetworkDrive MapLtr & ":", objPath
call ShowDrives
End Sub
'===============================================================================================
'CREATES ENTRY IN EVENT VIEWER FOR ERROR LOGGING PURPOSES
'-----------------------------------------------------------------------------------------------
Set oShell = CreateObject("Wscript.Shell")
Const EVENT_SUCCESS = 0
Const EVENT_FAIL = 1
if err.number <> 0 then
oShell.LogEvent EVENT_ERROR, "Drive Mapping Script Exited With An Error." & vbcrlf & "Error Number: " & err.number & vbcrlf & "Error: " & err.description
else
oShell.LogEvent EVENT_SUCCESS, "Drive Mapping Script Completed Successfully."
end if
'==============================================================================================
</Script>
<BODY STYLE="font:14 pt calibri medium; color:white; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#4169E1', EndColorStr='#1E90FF')">
<div style="width:100%; float:left">
<input style="width:100%; padding:7px;" type="BUTTON" value="Disconnect all mapped drives" onclick="DisconnectDrives">
<div align="center"><input style="width:32%; padding:7px;" type="BUTTON" value="Map S Drive" onclick="MapSDrive"> <input style="width:32%; padding:7px;" type="BUTTON" value="Map U Drive" onclick="MapUDrive"> <input style="width:32%; padding:7px;" type="BUTTON" value="Map P Drive" onclick="MapPDrive"></div>
<input style="width:100%; padding:7px;" id=addbutton type="button" value="Add Next Available Drive Letter" onClick="AddDriveLetter">
<span id=DataArea></span>
<br />
Currently connected to:
<textarea name="DispDrives" style="width:100%;" rows="7"></textarea>
</hr>
<div align="center"><input style="width:50%; padding:7px;" type="BUTTON" value="Done Mapping Drives" onclick="CloseWindow"> <input style="width:49%; padding:7px;" type="BUTTON" value="Try Again" onclick="Reload"></div>
</div>
<div style="width:100%;">
<input style="width:100%; padding:7px;" type="BUTTON" value="Printer Install" onclick="InstallPrinters">
</div>
</body>
</html>