I thought others might find this useful. I've been converting our login scripts from KIX to VBS and, much as I loathe KIX, I do admire its ability to handle INI files. So, when it came to writing the part of the script that mapped the user's network drives I wanted to have a similar method.
This is what I came up with in the end
Sub MapNetworkDrives
On Error Resume Next
'Map group-specific drives based on the entries in the MappedDrives.xml file.
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objSysInfo : Set objSysInfo = CreateObject("ADSystemInfo")
Dim objUser : Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Dim XMLDoc : Set xmlDoc = CreateObject("Microsoft.XMLDOM")
Dim MD_XMLPath : MD_XMLPath = GetLogonServer & "\NETLOGON\MWTEST\MappedDrives.xml"
Dim GroupObj,objDriveNode
'Load the XML file
xmlDoc.async = False
If objFSO.FileExists(MD_XMLPath) Then
xmlDoc.Load(MD_XMLPath)
'Compare each group the user is a member of and see if it is found in the XML file
'If so, retrieve the UNC path and drive latter to be mapped.
For Each GroupObj In objUser.Groups
Set objDriveNode = xmlDoc.selectSingleNode("//MappedDrives/Group[@Name = '" & Ucase(GroupObj.cn) & "']")
If Not objDriveNode Is Nothing Then
Err.Clear
objNetwork.MapNetworkDrive objDriveNode.childNodes(1).text & ":", objDriveNode.childNodes(0).text,True
If Err.Number <> 0 Then
WriteToErrorLog "Error mapping " & objDriveNode.childNodes(1).text & " to " & objDriveNode.childNodes(0).text
End If
End If
Next
End If
End Sub
The format of the XML file is as follows
<MappedDrives>
<Group Name="SERVER_GROUP1">
<UNCPath>\\MYSERVER\SHARENAME$</UNCPath>
<DriveLetter>G</DriveLetter>
</Group>
</MappedDrives>
Each drive mapping requires three nodes
Group, UNCPath and DriveLetter. The Group node has the attribute "NAME" which is equal to the name of the AD security group associated with the share. The UNCPath and drive letter nodes are pretty self-explanatory I guess ;)
Anyway, I thought this was a better way of doing things as it makes future management of this part of the login script easy. All people have to do is amend the XML file accordingly for each share.
I haven't included the WriteToErrorLog sub as it's obviously quite site-specific. Suffice to say it simply takes the string passed to it and writes it to a text file somewhere.
<message edited by ginolard on Tuesday, September 25, 2007 2:39 AM>