Skip to content

Instantly share code, notes, and snippets.

@ayancey
Created December 20, 2016 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayancey/10893ee6e372bee414b50d7c6a168f4e to your computer and use it in GitHub Desktop.
Save ayancey/10893ee6e372bee414b50d7c6a168f4e to your computer and use it in GitHub Desktop.
'''''''''''''''''''''''''''''
' 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""")
objFile.Close
' 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\"
objFSO.DeleteFile("remotemap.bat")
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