Description
Easily map a drive using the subst or net use command, picking the drive letter of your choice, and providing the proper credentials. It will also create a shortcut on your desktop and in the startup directory for your user.
Source Code
#include <File.au3>
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
#include <ButtonConstants.au3>
Global $bDirectory, $bComputer, $file, $mapCMD, $mapDRIVE, $bUser, $bPass, $mMap, $amapCMD, $aMapDrive, $aUser, $aPass, $mapPath
mapDriveGui()
Func mapDriveGui()
$mapdriveGen=GUICreate("MapDrive Generator",700,100)
$mapCMD=GuiCtrlCreateCombo("net use",10,50,75,30)
GUICtrlSetData(-1,"subst")
$mapDRIVE=GuiCtrlCreateCombo("m",100,50,75,30)
GuiCtrlSetData(-1,"b|i|j|k|l|n|o|p|q|r|s|t|u|v|w|x|y|z")
$bPath=GUICtrlCreateButton("Path...",200,50,75,30)
$bUser=GUICtrlCreateInput("Username",300,50,75,30)
$bPass=GuiCtrlCreateInput("Password",400,50,75,30)
$mMap=GuiCtrlCreateButton("Map it!",600,50,75,30)
$amapCMD=GUICtrlRead($mapCMD)
$aMapDrive=GuiCtrlRead($mapDRIVE)
$aUser=GUICtrlRead($bUser)
$aPass=GuiCtrlRead($bPass)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg= $bPath
$mapPath=FileSelectFolder("Choose your path wisely","network")
Case $msg= $mMap
mapdrive()
Exit
EndSelect
WEnd
EndFunc
Func mapdrive()
$amapCMD=GUICtrlRead($mapCMD)
$aMapDrive=GuiCtrlRead($mapDRIVE)
$aUser=GUICtrlRead($bUser)
$aPass=GuiCtrlRead($bPass)
$fINK=@DesktopDir&"\mapdrive.bat"
DirCreate("c:\_WorkstationBatch")
$file=FileOpen("c:\_Workstationbatch\mapdrive.bat",2)
If $aUser == "Username" AND $aPass =="Password" Then
FileWrite($file,$amapCMD&" "&$amapDrive&":"&" "&$mapPath)
Else
FileWrite($file,$amapCMD&" "&$amapDrive&":"&" "&$mapPath&" "&$aPass&" "&"/user:"&$aUser)
EndIf
FileClose($file)
If Not FileExists($file) Then
MsgBox(64,"MapDrive.bat","MapDrive.bat created!")
Else
MsgBox(64,"MapDrive.bat","Something went wrong!")
EndIf
FileCreateShortcut("c:\_WorkstationBatch\mapdrive.bat",$fINK)
FileCreateShortcut("c:\_WorkstationBatch\mapdrive.bat",@StartupDir&"\mapdrive.bat")
EndFunc
Screenshots