Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
' Purpose: Allows us to remotely map drives without psexec or knowing the user's password
' Requirements: Windows 7 (may support older OSes), Administrator (maybe)
' Written by: Alex Yancey
' Date: December 20, 2016
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("remotemap.bat")
drive_letter = InputBox("Map drive letter: ", "Remote Drive Mapping")
location = InputBox("Mapped location: ", "Remote Drive Mapping")
computer_name = InputBox("Destination computer: ", "Remote Drive Mapping")
username = InputBox("Destination username: ", "Remote Drive Mapping")
' Create a batch file which will unmap the current drive letter, map it to the correct location, and pop up a message box telling the user that the drive is mapped, and then deletes itself.
objFile.WriteLine("net use " & drive_letter & ": /delete")
objFile.WriteLine("net use " & drive_letter & ": " & location)
objFile.WriteLine("msg ""%username%"" Drive mapped")
objFile.WriteLine("(goto) 2>nul & del ""%~f0""")
' Copy the batch file to the user's startup folder. This will be run once, and then the batch file will be deleted.
objFSO.CopyFile "remotemap.bat", "\\" & computer_name & "\c$\Users\" & username & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
MsgBox("File created in startup folder. Instruct user to log out and log back in. Ensure that dialog box 'Drive mapped' pops up.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment