Been working on a fairly large script for security/auditing purposes and it came to me that the best time to run it was every time a user logs in... thus I decided to incorporate drive mappings and just have one script. Reading the FAQ I found the nice little script to map the drives using an XML file and groups. This sounded great so figure I'd try and incorporate that in. It would save me a ton of time overall and I'd be able to use the same login script for all users, just make changes to group membership. The problem is I'm running into problems with that part of the script. Perhas I'm missing something or just don't know enough but I'm stumped.
The following is the code from the FAQ modified slightly to try and get it to work with my systems. If the XML format from the FAQ is correct then mine should be correct as I just replaced the UNC path with one to one of my shares and changed the drive letter and group names. Obviously the Wscript.Echo commands are in there only for debugging purposes.
thanks
(PS: Yes, I'm calling the subroutine correctly) :)
quote:
Sub MapNetworkDrives On Error Resume Next
'Map group-specific drives based on the entries in the MappedDrives.xml file.
Dim objNetwork Dim objFSO Dim objSysInfo Dim objUser Dim XMLDoc Dim MD_XMLPath Dim GroupObj, objDriveNode Dim WSHShell, WSHProcess Dim LogonServer Set WSHShell = CreateObject("Wscript.Shell") Set WSHProcess = WSHShell.Environment("Process") Set objNetwork = CreateObject("WScript.Network") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objSysInfo = CreateObject("ADSystemInfo") Set objUser = "LDAP://" & objSysInfo.UserName Set xmlDoc = CreateObject("Microsoft.XMLDOM") LogonServer = WSHProcess("LogonServer") MD_XMLPath = LogonServer & "\NETLOGON\MapDrives.xml" User = "LDAP://" & objSysInfo.UserName Wscript.Echo User Wscript.Echo MD_XMLPath Wscript.Echo objUser.Groups '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
Sure... I use the full DNS name for my servers. (obviously not servername.domain.com). I've created groups called F-Drive and H-Drive for simplicity and testing and assigned myself to these groups so I can test.
Ok a few minor changes. DNS vs. NETBIOS name didn't make a difference. Now here is where it gets weird. The WSCRIPT.ECHO debugging lines... objUser which is assigned a value using a Set command returns a null value with the echo while user which is directly assigned a value returned the correct string.
Sub MapNetworkDrives On Error Resume Next
'Map group-specific drives based on the entries in the MappedDrives.xml file.
Dim objNetwork Dim objFSO Dim objSysInfo Dim objUser Dim XMLDoc Dim MD_XMLPath Dim GroupObj, objDriveNode Dim WSHShell, WSHProcess Dim LogonServer Set WSHShell = CreateObject("Wscript.Shell") Set WSHProcess = WSHShell.Environment("Process") Set objNetwork = CreateObject("WScript.Network") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objSysInfo = CreateObject("ADSystemInfo") Set objUser = chr(34) & "LDAP://" & objSysInfo.UserName & chr(34) Set xmlDoc = CreateObject("Microsoft.XMLDOM") LogonServer = WSHProcess("LogonServer") MD_XMLPath = LogonServer & "\NETLOGON\MapDrives.xml" User = "LDAP://" & objSysInfo.UserName Wscript.Echo User Wscript.Echo objUser Wscript.Echo MD_XMLPath Wscript.Echo objUser.Groups '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) & "']") Wscript.Echo 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