Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Drive Mapping with XML Help

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,58146
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Drive Mapping with XML Help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Drive Mapping with XML Help - 3/18/2008 8:26:10 AM   
  AAckley

 

Posts: 6
Score: 0
Joined: 3/14/2008
Status: offline
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 
 
 
Post #: 1
 
 RE: Drive Mapping with XML Help - 3/18/2008 8:39:09 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Could you post a sample of your XML please?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to AAckley)
 
 
Post #: 2
 
 RE: Drive Mapping with XML Help - 3/19/2008 12:01:20 AM   
  AAckley

 

Posts: 6
Score: 0
Joined: 3/14/2008
Status: offline
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. 


<MappedDrives>
<Group Name="F-Drive">
<UNCPath>\\servername.domain.com\applications</UNCPath>
<DriveLetter>F</DriveLetter>
  </Group>
  <Group Name="H-Drive">
<UNCPath>\\servername.domain.com\user_shares</UNCPath>
<DriveLetter>H</DriveLetter>
  </Group>
</MappedDrives>

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Drive Mapping with XML Help - 3/19/2008 12:13:28 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi AAckley,

one possible cause of problem is the case of your Group Name attribute:

<Group Name="F-Drive">

vs. the UCase in

Set objDriveNode = xmlDoc.selectSingleNode("//MappedDrives/Group[@Name = '" & Ucase(GroupObj.cn) & "']")

Good luck (you'll need it, because I did no tests - just speculated)!

ehvbs

(in reply to AAckley)
 
 
Post #: 4
 
 RE: Drive Mapping with XML Help - 3/19/2008 2:19:24 AM   
  AAckley

 

Posts: 6
Score: 0
Joined: 3/14/2008
Status: offline
No dice on the Ucase arguement.  I set everything from the group to the XML file to be all uppercase and still no go.

I'll try specifiying the server as a netbios name instead of dns to see if it makes a difference

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: Drive Mapping with XML Help - 3/19/2008 2:44:07 AM   
  AAckley

 

Posts: 6
Score: 0
Joined: 3/14/2008
Status: offline
 
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

(in reply to AAckley)
 
 
Post #: 6
 
 RE: Drive Mapping with XML Help - 3/19/2008 3:07:10 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi AAckley,

first get rid of the "On Error Resume Next". It hides blunders like

   Set objUser = chr(34) & "LDAP://" &  objSysInfo.UserName & chr(34)

(Set is used for assignment to an object)

(in reply to AAckley)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Drive Mapping with XML Help Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts