Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drive mapping not working

Status
Not open for further replies.

BDakis

MIS
Nov 26, 2003
12
US
I am having some trouble mapping a drive based on group membership. I can successfully build a dictionary of a user's groups, but cannot derive mappings based on this. I am including the code I have:


' First test for environment
If Domain = "Testing" Then
If IsMember("Group1") Then
wshNetwork.RemoveNetworkDrive aryDrivestoMap(9),1,1
wshNetwork.MapNetworkDrive aryDrivestoMap(9), "\\" & "Server" & "\" & arySharesToMap(9)
End If
Else
If Domain = "Production" Then
If IsMember("Group1") Then
wshNetwork.RemoveNetworkDrive "I:"
wshNetwork.MapNetworkDrive aryDrivestoMap(9), "\\" & "Server" & "\" & arySharesToMap(9)
End If


End If
End If

wscript.echo (wshnetwork.UserDomain)
if ismember("Group1") then
wscript.echo ("Successful") '(THIS WORKS)
End If
WScript.Quit(0)



' *************************************************************************
'
' IsMember function to query group membership
'
' sGroup (name of the group)
'
'
Function IsMember(sGroup)
Dim AdsPath, oUser, oGroup, oGroupDict
If IsEmpty(oGroupDict) Then
Set oGroupDict = CreateObject("Scripting.Dictionary")
oGroupDict.CompareMode = vbTextCompare
AdsPath = wshNetwork.UserDomain & "/" & wshNetwork.UserName
set oUser = GetObject("WinNT://" & AdsPath & ",user")
For Each oGroup in oUser.Groups
oGroupDict.Add oGroup.Name, "."
Next
Set oUser = Nothing
End If
IsMember = CBool(oGroupDict.Exists(sGroup))
End Function

' **************************************************************************

The function seems to be working as the if IsMember(Group1) then wscript.echo("Successful") command works. The only piece that doesn't work is the drive mapping piece.
As always, any help will be greatly appreciated!


Bill.
 
Have you tried this to see if args are correct ?
WScript.Echo aryDrivestoMap(9), "\\" & "Server" & "\" & arySharesToMap(9)

Hope This Help
PH.
 
Thanks for the reply!


It doesn't even work when I specify the drive letter, server and share.

 
BDakis, dont whatever you do implement this for a logon script, the users will kill, the time it takes to query AD to get the groups membership is crazy and try doing it over RAS.

from the look of your code you will call the IsMember many times, if you do you will query AD everytime, making things very slow.

its even worse than you think, some might say
do

Set objUserGroups = User.Groups

and then re-use this object, it only ends up doing exactly the same thing and takign forever everytime you work though the objUserGroups.

You are on the right lines with the building of a dictionary object. you just need to implement it globally.

i.e. make the call to AD once, populate your dictionary object once and then access that dictionary from then on

regards
richard
 
Richard-

Thanks for the reply! How can I make the dictionary global? I only have the function code listed once, and I reference it for only the 1 mapping...what am I doing wrong? I absolutely want to query AD only 1 time and then have the dictionary for reference (however many times I need it) but I am doing something wrong when I try to access the dictionary and mapp a drive off of that reference.


Bill.
 
all ive done is moved your Dim oGroupDict out of the function.
that way it will stay resident throughout the execution of your script.

otherwise you oGroupDict would have been destroyed when the function was out of scope and would have to be recreated each time

regards
richard




'''NB #####
Dim oGroupDict

'script stuff below here





Function IsMember(sGroup)
Dim AdsPath, oUser, oGroup
If IsEmpty(oGroupDict) Then
Set oGroupDict = CreateObject("Scripting.Dictionary")
oGroupDict.CompareMode = vbTextCompare
AdsPath = wshNetwork.UserDomain & "/" & wshNetwork.UserName
set oUser = GetObject("WinNT://" & AdsPath & ",user")
For Each oGroup in oUser.Groups
oGroupDict.Add oGroup.Name, "."
Next
Set oUser = Nothing
End If
IsMember = CBool(oGroupDict.Exists(sGroup))
End Function



 
We use the command line for drive mapping and it seems to work well. The first command call clears the drive letter while the second command call maps the drive to a location based on IP address.
'---------------------------------
'"z:" = the drive letter you are to use
'\\99.99.99.99 = IP address
'\z& = share name
'----------------------------------
cmdLine = "cmd /c net use z: /d"
Call RunCMD(cmdLine, True)

cmdLine = "cmd /c net use z: \\99.99.99.99\z$ /user:domainname\username password"
Call RunCMD(cmdLine, True)

'Runs command line sent
Sub RunCMD (cmdLine, Wait)
If wait Then
oShell.Run cmdLine, WindowMin, WaitonRet
Else
oShell.Run cmdLine, WindowMin, NoWaitonRet
End If
End Sub

The Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top