#194705 - 2009-07-13 12:13 PM
Loginscript whit ini file
|
bdirkx
Fresh Scripter
Registered: 2009-07-13
Posts: 8
Loc: Netherlands
|
Dear forum members.
I'm working in a very big enverment and now i want to make a kix script whit variable for reading a ini file for drive mappings. The drive mapping ar varaible whit groupmambership in AD.
I have made a script but it dosn't work. Can any body help me whit my problem.
Iám not a verry good scripter but i used a tool for making my script.
Here is a sample of my script.
Drivemapping.kix
;===============================================================
Call "MyFunctions.kix"
$aryGroups = GroupArray()
$strIniFile = "c:\kixwork\mappings.ini"
For Each $ae in $aryGroups
GroupMap($strIniFile,$ae)
Next
;===============================================================
Myfunction.kix
;===============================================================
Function GroupArray()
;===============================================================
Dim $i
Dim $strGrpLst
Dim $gName
$i = 0
$strGrpLst = ""
Do
$gName = EnumGroup($i)
$i = $i + 1
If Len($gName) > 0
If Len($strGrpLst) > 0
$strGrpLst = $strGrpLst + ","
EndIf
$strGrpLst = $strGrpLst + $gName
EndIf
Until Len($gName) = 0
$ary = Split($strGrpLst,",",-1)
;? "Before return array size is:" + Ubound($ary)
$GroupArray = $ary
EndFunction
;===============================================================
;===============================================================
Function GroupMap($inFile,$inSec)
;===============================================================
Dim $tmpDrv
$Sec = ReadProfileString($inFile,$inSec,"")
$aMaps = Split($Sec,Chr(10),-1)
For Each $a in $aMaps
$tmpDrv = ReadProfileString($inFile,$inSec,$a)
$aParms = Split($tmpDrv,",")
$act = UBound($aParms)
Use $aParms[0] + ":" $aParms[1]
Next
$GroupMap = 1
EndFunction
;===============================================================
Mapping.ini
;===============================================================
;==================================== ; Bebouw ;=Start============================== [GS_bebouw_acad] MapDrive1=F,\\dc-073\netapps$ MapDrive2=g,\\dc-073\usr$\%username% MapDrive3=N,\\dc-073\acad$ MapDrive4=O,\\dc-073\acad direct$ ;=End================================
;==================================== ; IBB Kondor ;=Start============================== [GS_IBB KONDOR_ACAD] MapDrive1=F,\\dc-034\netapps$ MapDrive2=g,\\dc-034\usr$\%username% MapDrive3=M,\\dc-034\acad$ MapDrive4=O,\\dc-034\acad direct$ ;=End================================
I hope somebody can help me whit my problem.
Greetings
Bart Dirkx
Edited by Mart (2009-07-13 01:10 PM) Edit Reason: Added code tags.
|
Top
|
|
|
|
#194708 - 2009-07-13 01:20 PM
Re: Loginscript whit ini file
[Re: bdirkx]
|
Mart
KiX Supporter
Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
|
Hi Bart,
Welcome to the board.
First: Please use the code tags when posting code (the # button when creating a post). This time I added them for you.
Second: Below is a small example of a logon script that enumerates all groups belongs to and then mapps drive based on data in the ini file.
Third: Be careful with hidden shares because kix might interpret the dollar sign as a variable. You can fix this with Setoption("NoVarsInStrings", "On") at the top of the script our you can double the dollar signs.
Script:
;Enumerate all group for the current user.
$goups = arrayenumgroup()
;Start the magic for each group.
For Each $group in $groups
;Read the number of drives to be mapped for each group.
$drives = ReadProfileString("c:\kixwork\mappings.ini", $goup, "NumberOfDrives")
;Map each drive.
For $i = 1 to $drives
;Read drive data from ini file.
$drive = ReadProfileString("c:\kixwork\mappings.ini", $goup, "MapDrive" + $i)
$drive = Split($drive, ",")
Use $drive[0] + ': "' + $drive[1] + '"'
Next
Next
;DO NOT MODIFY ANYTHING BELOW THIS LINE.
;IT IS A UDF AND IT COMES READY FOR USE.
;NAME ARRAYENUMGROUP
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;ACTION Creates an array of groups of which the current user is a member
;
;SYNTAX ARRAYENUMGROUP()
;
;PARAMETERS none
;
;RETURNS Array containing the group names
;
;REMARKS none
;
;DEPENDENCIES none
;
;EXAMPLE $retcode=arrayenumgroup()
;
Function arrayenumgroup()
Dim $retcode, $valuecounter, $currentvalue, $valuearray
$valuecounter=0
Do
$currentvalue=EnumGroup($valuecounter)
If $currentvalue<>259 And @ERROR=0
ReDim preserve $valuearray[$valuecounter]
$valuearray[$valuecounter]=$currentvalue
$valuecounter=$valuecounter+1
EndIf
Until $currentvalue=259 Or @ERROR
$arrayenumgroup=$valuearray
EndFunction
Ini file:
[GS_bebouw_acad] NumberOfDrives=4 MapDrive1=F,\\dc-073\netapps$ MapDrive2=g,\\dc-073\usr$\%username% MapDrive3=N,\\dc-073\acad$ MapDrive4=O,\\dc-073\acad direct$
Edited by Mart (2009-07-13 01:24 PM) Edit Reason: Typo.
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
#194713 - 2009-07-13 02:50 PM
Re: Loginscript whit ini file
[Re: bdirkx]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Welcome to KORG!
You can download a fully functional Kix-based login script from my web site. No coding needed - it has been used in large enterprise environments with many sites and thousands of users. In one large (3000 users across 250+ sites) the script performs 35 action decisions, maps the resulting drives and printers, displays an optional message, and runs two external commands in just 9 to 20 seconds (depending on the remote site link speed). The core code has been in use for well over a decade at over 100 sites around the world.
It uses an INI file for configuration, allows per-site and per-user config files, and supports mapping by group(s), OU, subnets. Group and OU processing can be "member of" or "not member of" one or more groups, including combinations (must be member of "Site1" group and not a member of "sales" group). It can also use a lookup table to modify the resource path (server name, share name, path, or any combination) based on userID, OU, Group, or Subnet.
The script is free, with full documentation and two free email support incidents. We do provide commercial, fee-based support for implementation, customization, and additional support.
For a no-code enterprise quality solution that you can have operational in just a few hours, give it a look. Select the Products page, go to the Admin Toolchest and click the Login Scripts link.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#194718 - 2009-07-13 03:54 PM
Re: Loginscript whit ini file
[Re: Mart]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Mart, that Mod Flag next to your name sure looks nice,
|
Top
|
|
|
|
#194728 - 2009-07-13 07:46 PM
Re: Loginscript whit ini file
[Re: Mart]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Yes I would say that most of Glenn's scripts are excellent but also a bit daunting for a new coder that isn't even familiar with all the commands and functions of KiXtart. Definitely worth looking at though as it is well documented and a good source of further learning KiXtart.
oh... and I've fixed your Title Mart
|
Top
|
|
|
|
#194839 - 2009-07-16 02:44 PM
Re: Loginscript whit ini file
[Re: Mart]
|
bdirkx
Fresh Scripter
Registered: 2009-07-13
Posts: 8
Loc: Netherlands
|
Mart
I will put a sample of the ini file on the forum.
Here is the sample of my inin file.
# login.ini file for login processing V2.6.1 # # Format of resource records is: # # [RESOURCE] # Type of Resource # CLASS=DISK|PRINT|COMMAND|MESSAGE # # Target ID to map share to # TARGET=drive: | [LPT#:] # # Path to shared resource # PATH=\\server\share[\path] # # Description of resource - renames drive map or displays a short message during mapping # DESC=Description # # Process record if admin / if not guest / if guest # PRIV=Admin|NoGuest|(blank) # # Process record only if member of at least one of listed groups # GROUPS=CSV list of permitted group memberships # # Process record only if member of at least one of listed OUs
# # By default, access is permitted if the user is a member of a defined Group or OU # Set the logic to AND to require membership of both Group and OU specifications # LOGIC=AND | OR # # Priority if multiple resources match - higher value wins. Used only for Drive and LPT#: mapping # to resove target conflicts # PRIORITY=# # # Process record only if one of the defined Connection Types # CONNTYPE=CON ICA RDP # # Process if the local computer is a laptop, is not a laptop, or always # LAPTOP = Y | N | (blank) # # Delay the specified number of seconds after displaying a message file # DELAY=number # # [COMMON] # A short message to display when there's an error mapping a resource HDMessage=Neem aub contact op met de helpdesk 088-1861300 als u een fout melding krijgt met inloggen!
# ConnType can be a list of session types - CON, RDP, and ICA - that are allowed to run login scripts # Define as CON RDP to run only with direct Console and Terminal Service connections, and not Citrix # Runs on all types if not defined. ConnType=
# ClearDriveMappings is a boolean value that indicates if all drive mappings should be cleared # when the login script starts ClearDriveMappings=y
# IgnoreDriveMappings is a comma-delimited string listing the drive letters that should not be unmapped # when ClearDriveMappings is true. This permits a set of drive letters that can be used for ad-hoc # connections that will not be unmapped. Valid only when ClearDriveMappings is true. # IgnoreDriveMappings=k
# ClearPrinterMappings is a boolean value that indicates if all printer mappings should be cleared # when the login script starts. This is currently under development and has no effect. ClearPrinterMappings=n
# ForceVisible is a boolean value that forces the login script to run in a maximized window ForceVisible=y
# Minimum tune to display the login script window (in seconds) # Insures that the window is displayed for at least "n" seconds in fast environments MinimumDisplayTime=6
# FlushTokenCache defines the number of days before the Kixtart domain token cache should be cleared. # If the value is 0 or not defined, the cache is never cleared. A value of -1 always clears the cache. # The default value is 7. The actual value should be based on the number of AD changes made within # a defined time, lowering this number when many changes are made. FlushTokenCache=7
# OUOffset is a value that defines the field offset of the LDAP string where the user's OU is defined # For example, if the DN is OU=users,OU=department xx,OU=DepartmentGroup,DC=domain,DC=com - the most specific # OU field is "department xx", which has an index offset of 1. Most structures that have this format would # use an offset of 1, if the structure looks like OU=department xx,OU=DepartmentGroup,OU=users... the offset # would be zero instead. OUOffset=1
# Version 2.6.0 introduces internationalization of messages. If the languageID is not specified, # it defaults to 0 (US English). This setting only affects user messages and not debug messages. # If LanguageID=-1 (negative one), then the language definitions in UserLang.kix will be loaded # if present. If the file is not present, English will be used. You can also use the standard # rewrite / lookup processing - &SITE:table&, &OU:table&, or &SUBNET:table& - to define languages # by AD Site, OU, or network subnet. Failed or invalid lookups default to English. LanguageID=0
# RunSilent will suppress all output when set to True (Y/N) - default is Display Messages (N) # Even if RunSilent is true, MESSAGE class resources will display, and resource processing # errors will cause an error message to display. RunSilent will also turn off the ForceVisible # setting, but will not force the window to be minimized RunSilent=N
# Allowed / Denied domains - comma-delimited lists of AD domain names that are allowed or denied # This is useful in trusted domain situations where a user logs into a computer with trusted # credentials. The computer does not have access to the user's home domain resources, so mapping # of those resources should not be done. A list of allowed or denied domains can be defined, but # only one or the other really makes sense - both are provided to permit using the shortest list. AllowedDomains=DM001 DeniedDomains=ThatTrustedDomain
DEBUG=Y
######################################## # # # resource mapping definitions follow # # # ########################################
# [RESOURCE_ID] # CLASS=DISK | PRINT | MESSAGE | COMMAND # TARGET=drive letter | printer id (LPT#:) # PATH=UNC path to resource | HOME # DESC=description # PRIV=Admin | Guest | NoGuest # GROUPS=list of groups permitted to connect # OUS=list of OUs permitted to connect # PRIORITY=priority of resource when multiple PATHS are defined for one TARGET # LAPTOP=Y|N| Process for laptop, non-laptop, or any system type # LOGIC=AND|OR Defines the logic used to process both Group and OU access restrictions
[IBB Kondor] CLASS=DISK TARGET=F: PATH=\\dc-034\netapps$ DESC=Netapps CLASS=DISK TARGET=G: PATH=\\dc-034\USR$\%USERNAME% DESC=USERSHARE AUTOCAD CLASS=M: PATH=\\dc-034\acad$ DESC=Autocad CLASS=O: PATH=\\DC-034\ACAD DIRECT$ DESC=AUTOCAD SYNCHRONISATIE PRIV=GUEST GROUPS=GS_IBB Kondor_ACAD OUS=
[BEBOUW] CLASS=DISK TARGET=F: PATH=\\dc-073\netapps$ DESC=Netapps CLASS=DISK TARGET=G: PATH=\\dc-073\USR$\%USRENAME% DESC=USERSHARE AUTOCAD CLASS=N: PATH=\\dc-073\acad$ DESC=Autocad CLASS=O: PATH=\\DC-073\ACAD DIRECT$ DESC=AUTOCAD SYNCHRONISATIE PRIV= GROUPS=GS_BEBOUW_ACAD OUS=
[Van Agtmaal] CLASS=DISK TARGET=F: PATH=\\dc-075\netapps$ DESC=Netapps CLASS=DISK TARGET=G: PATH=\\dc-075\USR$\%USRENAME% DESC=USERSHARE AUTOCAD CLASS=N: PATH=\\dc-075\acad$ DESC=Autocad CLASS=O: PATH=\\DC-075\ACAD DIRECT$ DESC=AUTOCAD SYNCHRONISATIE PRIV= GROUPS=GS_Van Agtmaal_ACAD OUS=
#========================================================== # MESSAGE OF THE DAY Definitions # users will see all that they are allowed to, up to the first 10 defined
# MOTD for Admin group members #[MOTD_ADMINS] #CLASS=MESSAGE #PRIV=ADMIN #PATH=\\server\users\ADMIN.txt #DESC=Admin Alert
# MOTD for associates group members #[MOTD_Work] #CLASS=MESSAGE #PATH=\\server\users\MOTD.txt #DESC=Message of the day #GROUPS=associates
#========================================================== # PRINT definitions # CLASS=PRINT # TARGET=LPT1: - LPT9: for 16b systems, null for 32b systems # If TARGET is null, the resource will only be mapped on 32b systems # PATH=\\server\printer_share # PATH can also be the reserved word "DEFAULT", and the path defined in the LP # environment variable will be used. # PRIV=null (anybody) | ADMIN | NOGUEST # GROUPS=comma-delimited list of groups whose members are allowed to connect to this resource # # Systems are prevented from mapping to localy defined printers.
# Lexmark Optra Se 3455 - HP/PCL #[OPTRA_HP] #CLASS=PRINT #PATH=\\printserver\Optra #GROUPS=+Site0 Users #SETDEFAULT=Y
# Lexmark Optra Se 3455 - PostScript #[OPTRA_PS] #CLASS=PRINT #PATH=\\printserver\OptraPS #GROUPS=+Site0 Users
# Printer at site 1 #[Site1_Printer] #CLASS=PRINT #PATH=\\s1ps00\printer #GROUPS=+Site1 Users #SETDEFAULT=Y
#========================================================== # COMMAND definitions # CLASS=COMMAND # PATH=\path\to\command # PATH can be a physical path or a UNC # PRIV=null (anybody) | ADMIN | NOGUEST # GROUPS=comma-delimited list of groups whose members are allowed to execute this command
When i run the kixtart what's came with the download from glenn.
It will start reading the login.ini script and it stops by the first f: and says the script is done. But i don't see the mapping in net use and don't see the other drive mappings.
Can anybody see the error.
And sorry but the avatar is also my home town.
_________________________
Greetings
Bart Dirkx
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
2 registered
(morganw, mole)
and 414 anonymous users online.
|
|
|