VBS Drive Mapping script

This is a great starter script for an individual who wants to get away from bat files. This script runs silently will check to see the availability of the drives to be mapped, disconnect the conflicts, then map the 3 drives specified. The script is well documented so changing to fit your needs is trivial even if you know nothing about vbs.

Source Code

This script has not been checked by Spiceworks. Please understand the risks before using it.

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

'This is the default logon script for all users. This script was created by Adam Walter. 'The purpose of this script is to disconnect and map 3 specified drives. This script 'will allow users to map their own drives without fear of losing them when the logon script kicks in.'The three drives to be mapped will be as follows. You will want to change the paths, find and replace'will work fine here, replacing SERVER with your servername, Common with your Common shared folder. Software 'with your software or other specific folder. More Drives can easily be mapped. If you do not wish a drive'to be mapped you can omit the drive in the mapping section at the end.'P:\ == \\SERVER\<username>'F:\ == \\SERVER\Common 'G:\ == \\SERVER\Software'------------------------------------------------------------------------------------------OptionExplicit'strCommonLetter will be the main Share drive letter.'strUserLetter will be the user's home directory drive letter.'strHomeServer will be the Fileserver UNC.'strSoftwareFolder will be the Folder for the Software Share.'strUsername will be the %username% for the home directory.'Define ObjectsDimobjNetwork,strUserName,strSoftwareFolder,strUserLetter,strCommonLetter,strSoftwareLetter,strCommonFolder,strHomeServer,WshShell,colDrives,WSHNetwork,i'Define Network Objects for system calls.SetobjNetwork=CreateObject("WScript.Network")SetWSHNetwork=WScript.CreateObject("WScript.Network")'Enumerate network drives into a collection object so we know what drives are already mapped.SetcolDrives=WSHNetwork.EnumNetworkDrivesstrUserLetter="P:"strCommonLetter="F:"strSoftwareLetter="G:"strHomeServer="\\SERVER\"strUserName=strUserNamestrSoftwareFolder="Software"strCommonFolder="Common"'This will remove Pre-existing user and custom drives in case they were mapped manually.'To add a disconnect for an additional drive just add an additional Or statement in.'If there are more than 0 drives...IfcolDrives.Count<>0Then' Check the drives to see if any of the drive letters to be mapped are already in use, if they are, disconnect them.Fori=0TocolDrives.count-1Step2If(ColDrives(i)=strUserLetter)Or(ColDrives(i)=strCommonLetter)Or(ColDrives(i)=strSoftwareLetter)ThenWshNetwork.RemoveNetworkDrivecolDrives(i)EndIfNextEndIf'P:\ Map personal network drive for logged on user to P.objNetwork.MapNetworkDrivestrUserLetter,strHomeServer&strUserName'F:\ Map Common drive to F.objNetwork.MapNetworkDrivestrCommonLetter,strHomeServer&strCommonFolder'G:\ Map Software drive to G.objNetwork.MapNetworkDrivestrSoftwareLetter,strHomeServer&strSoftwareFolder'End of Drive Mapping Section you can add more vbs commands below'------------------------------------------------------------------------------------------