Question : VBS persistant drive mapping

This is a working logon script but I would like the drive mappings to be persistant. Is there any way to do that with VBS?
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:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
on error resume next							

Set objSysInfo = CreateObject("ADSystemInfo")					'Retrieves AD info example: CN=Users, OU=Ft_collins, dc=aei, dc=com
Set objNetwork = CreateObject("Wscript.Network")

strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)					'Bind above to that user’s Active Directory account

strUserName = objUser.samAccountName						'Determines User's logon name and stores it in a variable

strOUPath = objUser.Parent
arrContainers = Split(strOUPath, ",")
arrOU = Split(arrContainers(1), "=")
strOU = arrOU(1)

Dim GroupObj

Select Case strOU

Case "SIte 1"

strDriveH = "\\server 1\Users\" & strUserName				'Sets strDriveH variable to Home drive location
strDriveG = "\\server 1\groups"						'Sets strDriveG variable to Groups drive location
strDriveP = "\\server 1\public"						'Sets strDriveP variable to Public drive location
strDriveX = "\\server 2\applic" 					'Sets strDriveX variable to Applic drive location
strDriveI = "\\server 3\groups"						'Sets strDriveI variable to Engineering Groups drive location

For Each GroupObj In objUser.Groups 					'Maps the I: Drive based on the group memebership to ENG
  if (StrComp(GroupObj.cn,"ENG") = 0) then
    objNetwork.RemoveNetworkDrive "I:", True, True 				'Removes previous mapping to I Drive
    objNetwork.MapNetworkDrive "I:", strDriveI 					'Maps I Drive
  end if 
Next

Case "Site 2"

strDriveH = "\\server 4\Users\" & strUserName			'Sets strDriveH variable to Home drive location
strDriveP = "\\server 4\public"							'Sets strDriveP variable to Public drive location
strDriveX = "\\server 4\applic"							'Sets strDriveX variable to Applic drive location
strDriveG = "\\server 4\groups"							'Sets strDriveG variable to Groups drive location

Case "Site 3"

strDriveH = "\\server 5\Users\" & strUserName			'Sets strDriveH variable to Home drive location
strDriveG = "\\server 5\groups"							'Sets strDriveG variable to Groups drive location
strDriveP = "\\server 5\public"							'Sets strDriveP variable to Public drive location
strDriveX = "\\server 5\applic"							'Sets strDriveX variable to Applic drive location

Case "Site 4"

strDriveH = "\\server 6\Users\" & strUserName					'Sets strDriveH variable to Home drive location
'strDriveG = "\\server 6\groups"						'Sets strDriveG variable to Groups drive location
strDriveP = "\\server 6\public"							'Sets strDriveP variable to Public drive location
strDriveX = "\\server 6\applic"							'Sets strDriveX variable to Applic drive location

Case "Site 5"

strDriveH = "\\server 7\Users\" & strUserName                                   'Sets strDriveH variable to Home drive location
strDriveG = "\\server 7\groups"                                                 'Sets strDriveG variable to Groups drive location
strDriveP = "\\server 7\public"                                                 'Sets strDriveP variable to Public drive location
'strDriveX = "\\server 7\applic"                                                'Sets strDriveX variable to Applic drive location
strDriveY = "\\server 1\groups"                                    'Sets strDriveY variable to Accounting Groups drive location

For Each GroupObj In objUser.Groups                                             'Maps the Y: Drive based on the group membership to Public_She_Finance
  if (StrComp(GroupObj.cn,"Public_She_Finance") = 0) then
    objNetwork.RemoveNetworkDrive "Y:", True, True                              'Removes previous mapping to Y Drive
    objNetwork.MapNetworkDrive "Y:", strDriveY                                  'Maps Y Drive
  end if  
Next

Case "Site 6"

strDriveH = "\\server 8\Users\" & strUserName					'Sets strDriveH variable to Home drive location
strDriveP = "\\server 8\public"							'Sets strDriveP variable to Public drive location
strDriveX = "\\server 2\applic" 						'Sets strDriveX variable to Applic drive location
strDriveG = "\\server 8\groups"							'Sets strDriveG variable to Groups drive location


'objNetwork.RemoveNetworkDrive "V:", True, True					'Removes previous mapping to V Drive
'objNetwork.MapNetworkDrive "V:", strDriveX					'Maps V Drive

'objNetwork.RemoveNetworkDrive "I:", True, True					'Removes previous mapping to I Drive
'objNetwork.MapNetworkDrive "I:", strDriveX					'Maps I Drive

'objNetwork.RemoveNetworkDrive "M:", True, True					'Removes previous mapping to M Drive
'objNetwork.MapNetworkDrive "M:", strDriveX					'Maps M Drive

'objNetwork.RemoveNetworkDrive "F:", True, True					'Removes previous mapping to F Drive
'objNetwork.MapNetworkDrive "F:", strDriveX					'Maps F Drive

Case "Site 7"

strDriveH = "\\server 9\Users\" & strUserName					'Sets strDriveH variable to Home drive location
strDriveG = "\\server 9\groups"							'Sets strDriveG variable to Groups drive location
strDriveP = "\\server 9\public"							'Sets strDriveP variable to Public drive location
strDriveX = "\\server 2\applic"							'Sets strDriveX variable to Applic drive location

Case "Site 8"

strDriveH = "\\server 10\Users\" & strUserName					'Sets strDriveH variable to Home drive location
strDriveG = "\\server 10\groups"							'Sets strDriveG variable to Groups drive location
strDriveP = "\\server 10\public"							'Sets strDriveP variable to Public drive location
strDriveX = "\\server 10\applic"							'Sets strDriveX variable to Applic drive location

Case "Site 9"

strDriveH = "\\server 11\Users\" & strUserName					'Sets strDriveH variable to Home drive location
strDriveG = "\\server 11\groups"							'Sets strDriveG variable to Groups drive location
strDriveP = "\\server 11\public"							'Sets strDriveP variable to Public drive location
strDriveX = "\\server 11\applic"							'Sets strDriveX variable to Applic drive location

Case "Site 10"

strDriveH = "\\server 1\Users\" & strUserName					'Sets strDriveH variable to Home drive location
strDriveG = "\\server 1\groups"							'Sets strDriveG variable to Groups drive location
strDriveP = "\\server 1\public"							'Sets strDriveP variable to Public drive location
strDriveX = "\\server 2\applic" 						'Sets strDriveX variable to Applic drive location

Case "Site 11"

'Manually map drives upon request

Case "Site 12"

'msgbox "Map your own drives slacker!", vbinformation

Case else

End Select

'Uncomment the following lines for testing
'msgbox "Your current OU is - " & strOU & Chr(13) & Chr(10) & "Set H: to - " & strDriveH & Chr(13) & Chr(10) & "Set G: to - " & strDriveG  & Chr(13) & Chr(10) '& "Set P: to - " & strDriveP & Chr(13) & Chr(10) & "Set X: to - " & strDriveX, vbInformation


							

'objNetwork.RemoveNetworkDrive "H:", True, True					'Removes previous mapping to H Drive
objNetwork.RemoveNetworkDrive "G:", True, True					'Removes previous mapping to G Drive
objNetwork.RemoveNetworkDrive "P:", True, True					'Removes previous mapping to P Drive
objNetwork.RemoveNetworkDrive "X:", True, True					'Removes previous mapping to X Drive

WScript.Sleep 500

objNetwork.MapNetworkDrive "H:", strDriveH					'Maps H Drive
objNetwork.MapNetworkDrive "G:", strDriveG					'Maps G Drive
objNetwork.MapNetworkDrive "P:", strDriveP					'Maps P Drive
objNetwork.MapNetworkDrive "X:", strDriveX					'Maps X Drive

Answer : VBS persistant drive mapping

http://msdn.microsoft.com/en-us/library/8kst88h6(VS.85).aspx

Everywhere you have "objNetwork.MapNetworkDrive"    add    , True       onto the end of each line.  That will cause the mapping to be stored in the user's profile information, thus making it persistent.


HTH,
exx
Random Solutions  
 
programming4us programming4us