#38086 - 2003-03-20 10:59 AM
HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Kris
Fresh Scripter
Registered: 2003-03-20
Posts: 13
Loc: Belgium
|
Below is the scripts I made. For drivemappings, I get the servername out of the user's local groups and the sharename out of the user's global groups. PROBLEM: Some users are in several matching local and global groups so they will get the same drivemapping twice. How can I prevent this or delete an identical drivemapping on another driveletter?
Break on ; Make this script interruptable using close or ctrl-C Debug OFF ; cls
; Standard reserved driveletters $WerkLetter = "GJKL-" $ApplLetter = "QRP-" $ProjLetter = "STUV-"
; Get all Local and Global Groups $arLocal = GetUserLocalGroups() $arGlobal = GetUserGlobalGroups()
; Set LogonDomain $strDomain = @LDOMAIN
; walk all Local Groups For Each $strLocalGroup in $arLocal
;? $strLocalGroup ; Get all Global Groups in this LocalGroup $arGlobalInLocal = GetGlobalInLocal($strLocalGroup, $strDomain)
; Walk all Global Groups in this LocalGroup For Each $strGlobalInLocal in $arGlobalInLocal
; ? $strGlobalInLocal
For Each $strglobal in $arGlobal ; ? $strglobal If $strglobal = $strGlobalInLocal $line = "\\" + $strLocalGroup + "\" + $strglobal ? $line EndIf
; Build share name ; MakeMapping($strLocalGroup, $strGlobalLocalGroup) ; Endif Next Next Next
Function GetUserLocalGroups()
$LTeller = 0 Do $LGroup = EnumLocalGroup($LTeller) $LTeller=$LTeller+1 $GetUserLocalGroups = $GetUserLocalGroups + ";" +$LGroup Until Len($LGroup) = 0 $GetUserLocalGroups = Split($GetUserLocalGroups, ";")
EndFunction
Function GetUserGlobalGroups()
$GTeller = 0 Do $GGroup = EnumGroup($GTeller) $GTeller=$GTeller+1 $GetUserGlobalGroups = $GetUserGlobalGroups + ";" +$GGroup Until Len($GGroup) = 0 $GetUserGlobalGroups = Split($GetUserGlobalGroups, ";")
EndFunction
Function GetGlobalInLocal($strLocalGroup, $strDomain)
Dim $i,$error,$line Dim $array[255] Dim $ReDim $ReDim = Ubound($array) Dim $tempfile $tempfile = "%temp%\pipe.tmp"
If Exist("$tempfile") Del("$tempfile") EndIf Shell '%comspec% /c local "$strLocalGroup" "$strDomain" > "$tempfile" 2>nul' $error = @error If Open (10, "$tempfile") = 0 $i = 0 $line = ReadLine(10) While NOT @error If $line $array[$i] = $line If $i = $ReDim $ReDim = $ReDim*2 ReDim preserve $array[$ReDim] EndIf $i = $i + 1 EndIf $line = ReadLine(10) Loop $=Close(10) Del "$tempfile" If $i > 0 ReDim preserve $array[$i-1] $GetGlobalInLocal=$array Else $GetGlobalInLocal = 0 EndIf Exit $error Else $GetGlobalInLocal = 0 Exit @error EndIf
EndFunction
;Parse servername from LocalGroup name Function GetServerFromLocalGroup($strLocalGroup)
$GetServerFromLocalGroup = SubStr($strLocalGroup, 3, Len($strLocalGroup) - 2)
EndFunction
;Parse ShareName from GlobalGroup name Function GetShareNameFromGlobalGroup($strGlobalGroup)
$GetShareNameFromGlobalGroup = SubStr($strGlobalGroup, InStr($strGlobalGroup, "_") + 1)
EndFunction
Function CheckStringINArray($arGlobal, $strGlobalLocalGroup)
$CheckStringINArray = 0 For Each $strToCheck IN $arGlobal
?$strToCheck ?$strGlobalGroup If ($strToCheck == $strGlobalGroup) $CheckStringINArray = 1 EndIf Next
EndFunction
Function MakeMapping($strLocalGroup, $strGlobalGroup)
? "Share: \\" + GetServerFromLocalGroup($strLocalGroup) + "\" + GetShareNameFromGlobalGroup($strGlobalGroup)
EndFunction
|
|
Top
|
|
|
|
#38087 - 2003-03-20 01:00 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You can build a string for the path e.g. "\\server\share" and push it into a unique array using my HASH() UDFs. Then when you read "keys" from the HASH you will only get unique entries.
|
|
Top
|
|
|
|
#38091 - 2003-03-20 02:42 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
#38097 - 2003-03-20 03:53 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Kris
Fresh Scripter
Registered: 2003-03-20
Posts: 13
Loc: Belgium
|
Thanx 4 all the efforts so far guys... The problem is not solved yet ... The solution must work on NT4, W2K and XP, so it must'nt use WSH but ONLY kix or a batchjob.
Peace!
|
|
Top
|
|
|
|
#38099 - 2003-03-20 04:40 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Kris, did I misunderstand your problem. when Iread your original post I thought that the script you used and the methodology of using the groups had your script attempt to map the same share name more than one time. If this is a scripting issue my suggestion would eliminate the the duplicate attempts to map the same drive.
If you problem is not that you code is making multiple attempts to map the same drive, and it is in fact that multiple drives appear to be mapped to the same server\share location that is not a result of your script, then you issue in not your script. Please clarify which problem you are experiencing.
Include writing a logfile of all mapping activity in your script, how does that compare with the drives currnely mapped after the logon script has finished? Are the extra drives always to the same location?
|
|
Top
|
|
|
|
#38100 - 2003-03-25 01:36 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Kris
Fresh Scripter
Registered: 2003-03-20
Posts: 13
Loc: Belgium
|
I think Howard Bullock has a pretty good solution with his HASH (UDF) function but I still didn't manage to get the script to work with HASH (UDF). Perhaps the complexity is too high...
|
|
Top
|
|
|
|
#38101 - 2003-03-25 01:57 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Nothing is too complex. Simply write more complex code.
I have to study your original post to determine exactly what it is you are doing. I may have time to review it some time this morning. [ 25. March 2003, 13:57: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#38102 - 2003-03-25 02:18 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Let me see if I understand what you are attempting to do...
1. You have global groups (named using a share name) that contain people that can access a given server.
2. You have local groups on a server (named after servers) that contain people that can access a given share.
3. The local group can contain global groups - why?
Please describe the business/security process you want to employ.
Please confirm that the problem of the duplicate groups arises from the fact that the person is a member of a global group and that the same of different global group containing the same person is also located in the local group.
{edit} changed #1 and #2. Had Group to server/share relation reversed. [ 25. March 2003, 14:30: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#38103 - 2003-03-25 02:29 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Kris
Fresh Scripter
Registered: 2003-03-20
Posts: 13
Loc: Belgium
|
Howard,
Local groups do contain global groups and the group policy is unchangeable since this is a script for the belgian and european government. The roots of the organisation are soo deep , that no-one will change this before we start an Active Directory rollout next year... So the only solution for now and the future is make this script work for all the departments of the gouvernments. Do you know how to configure you're HASH (udf) in this script to remove or prevent potentially double drive mappings?
|
|
Top
|
|
|
|
#38104 - 2003-03-25 02:37 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I think so.
This is what I have so far: code:
Function GetServerFromLocalGroups() Dim $LTeller, $LGroup $LTeller = 0 Do $LGroup = EnumLocalGroup($LTeller) $LTeller=$LTeller+1 Hash("MyShares", SubStr($LGroup, InStr($LGroup, "_") + 1, 1) Until Len($LGroup) = 0 EndFunction Function GetSharesFromGlobalGroups() Dim $GTeller, $GGroup $GTeller = 0 Do $GGroup = EnumGroup($GTeller) $GTeller=$GTeller+1 Hash("MyServers", SubStr($GGroup, 3, Len($GGroup) - 2, 1) Until Len($GGroup) = 0 EndFunction
This code replaces several of your original functions.
What needs to be worked on now is the listing of the global groups in locals groups and adding the additional shares (from Global groups names) to the "MyShares" HASH.
Then you simply: code:
For each $Server in HashKeys("MyServers") For each $Share in HashKeys("MyServers") use $drive "\\"+$Server+"\"+$Share next next
I haven't quite figured out where you link the drive letter to the server\share yet.
Does this seem to be going in the right direction? [ 25. March 2003, 14:38: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#38105 - 2003-03-25 02:42 PM
Re: HOW CAN I REMOVE/PREVENT DOUBLE DRIVEMAPPINGS?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
This seems somewhat confusing and potentially links inappropriate server names to the wrong shares.
Can you provide more detail in the actually naming conventions of the groups (local and global) so that we can understand your implementation better?
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 837 anonymous users online.
|
|
|