#162790 - 2006-06-02 02:31 PM
loop mapping network drives
|
chein
Fresh Scripter
Registered: 2006-06-02
Posts: 8
|
Hello,
I am new to KiXtart and ready to replace the existing "netlogon.cmd" with my first KiXtart-script. It might not look so good, but it works (somehow).
Short overwiew: /* Server */ --> Create var for the servers. /* Mappings */ --> Create var for "usergroups" ($MAP_USER) "Server+Share" ($MAP_Server), "drive" ($MAP_LW) and "userparameters" ($MAP_USP) /* Execute */ --> to combine the var from /* Mapping */ into commands
The Code-segment below is cut short
Code:
/* Server */ $fileserver="myfileserver" $baan3="mybaanserver"
/* Mappings */ $MAP_User_220="domain\usergroup-all" $MAP_Server_220="$fileserver\group" $MAP_LW_220="G:"
$MAP_USER_221="domain\usergroup-all" $MAP_SERVER_221="$fileserver\home\@USERID" $MAP_LW_221="H:"
; etc.
$MAP_USER_230="domain\usergroup-itadm" $MAP_SERVER_230="$baan3\it" $MAP_LW_230="S:" $MAP_USP_230="/user:itadm"
/* Execute */ IF INGROUP ($MAP_USER_220) = 1 ? "connect $MAP_LW_220 " shell "net use " + $MAP_LW_220 + " \\$MAP_Server_220 " + $MAP_USP_220 ENDIF IF INGROUP ($MAP_USER_221) = 1 ? "connect $MAP_LW_221 " shell "net use " + $MAP_LW_221 + " \\$MAP_Server_221 " + $MAP_USP_221 ENDIF ; etc.
This works fine, but for every new networkshare (i.e. no.231) I have to create 3-4 entries in /* Mappings */, each with 231 and an entry in /* Execute */ with all 231 to map it. As I tried to make everything a var, I would like to use in /* Execute */ only ONE loop instead, like:
For $count = 220 to 230 step 1 IF INGROUP ($MAP_USER_XXX) = 1 ? "connect $MAP_LW_XXX " shell "net use " + $MAP_LW_XXX + " \\$MAP_Server_XXX " + $MAP_USP_XXX ENDIF NEXT
"XXX" should be increased every step and refer back to the vars in /* Mappings */ So people will only have to add new mappings in /* Mappings */ and raise the loop counter "to 232" and the skript does the rest itself in the loop. 10 possible Mappings --> 1 Loop 250 possible Mappings --> still 1 loop, but more vars in /* Mappings */
Is this somehow possible?
I tried to include $count instead of "XXX", added (, " and + I tried to slpit the vars in an array, join them back, but I never got the loop to use the vars from /* Mappings */. It alway used the vars as strings or not at all.
Any ideas, comments or commands?
Regards, Carsten
|
|
Top
|
|
|
|
#162791 - 2006-06-02 03:20 PM
Re: loop mapping network drives
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
My first suggestion is not to use the SHELL command. Read the manual about the USE command. Also search the board for any number of MapDrive UDF's that will make you life easier.
Once you understand these aspects then look into your looping.
|
|
Top
|
|
|
|
#162794 - 2006-06-06 07:56 AM
Re: loop mapping network drives
|
chein
Fresh Scripter
Registered: 2006-06-02
Posts: 8
|
Thanks for the reminder, yes, I wanted to test the possibility to use at least two different files for 1.- parameter/config for the skript (edited for new mappings, new server etc.) 2.- skript itself (edited when changes in 1.- are not enough) Will be the next thing on my "try it with KiX" -list.
|
|
Top
|
|
|
|
#162795 - 2006-06-06 08:11 AM
Re: loop mapping network drives
|
chein
Fresh Scripter
Registered: 2006-06-02
Posts: 8
|
I am abusing the "shell" command, because I failed "use" to ask me for my password fast enough. (like: Net use x: \\server\share * /user:...) Pardon me my impatience, will read the reference more precisely ;-)
|
|
Top
|
|
|
|
#162796 - 2006-06-06 08:21 AM
Re: loop mapping network drives
|
chein
Fresh Scripter
Registered: 2006-06-02
Posts: 8
|
I did use "shell net use" instead of "use", because I failed "use" to ask me for my password by force. Yes, I will read the reference on that one.
[...] Also search the board for any number of MapDrive UDF's that will make you life easier.[...]
Thank you for the information with "UDF's". Now I have got a direction to search.
|
|
Top
|
|
|
|
#162798 - 2006-06-21 02:20 PM
Re: loop mapping network drives
|
chein
Fresh Scripter
Registered: 2006-06-02
Posts: 8
|
Hello,
so I am using UDF and INI by now and can run a loop. Great. Smaller skript (one looped "use") and an INI file for a lot of parameters, that can be edited even by those who never touched KiXtart before. Unfortunately using the INI leads to another problem for me.
The UDF is not included in this little example, the mapping of the drives will be executed with a Call fnMapDrive in kixbiblio.udf in the real skript.
file: kixlogon.kix Code:
$inipath = "D:\Tools\KiX\kixlogin.ini" FOR $Counter = 1010 to 1030 step 10 $aktDrive = ReadProfileString("$inipath", "$Counter", "Drive") $aktPath = ReadProfileString("$inipath", "$Counter", "Path") $aktGroup = ReadProfileString("$inipath", "$Counter", "Group") IF INGROUP ($aktGroup) = 1 ? "Connecting $aktdrive " use $aktdrive "\\"+"$aktpath" ENDIF next
file: kixlogin.ini Code:
[1010] Drive="G:" Path="server1\all" Group="domain\company-all-g"
[1020] Drive="H:" Path="server1\home\@userid" Group="domain\company-all-g"
[1030] Drive="I:" Path="server1\it$" Group="domain\IT-read-g","domain\IT-write-g"
This works for 1010 well. 1020 works not because of @userid beeing not translated into the username, if I put my loginname/username instead of @userid it works, but is not var anymore. 1030 works not because of the two Groups, if I only use one, it works. But using the "Group1 or Group2 or Group3"-Array for the mapping keeps the INI smaller.
1020 and 1030 do work if I include them as $xy="..." into the skript itself. (Like done before in one big skript and not in the INI)
We are having a lot of mappings depending upon membership in one OR another group, and I would not like to have all of those as single entries in the INI file. Would be big and ugly like the netlogon.cmd before.
The @userid - feature is needed within the loginskript, because we have a lot of mappings that will be made with username from mydomain, but also with the same username from anotherdomain. net use x: \\server1\share1 /user:mydomain\JohnDoe net use y: \\server2\share2 /user:anotherdomain\JohnDoe net use z: \\server3\share3 /user:yetanotherdomain\JohnDoe
I am at the point to use a loop with the INI, but fail at most mappings, or to keep all in one working skript without a loop. Any commands, ideas, chars like ""() or topics in the forum I did miss?
Regards, Carsten
|
|
Top
|
|
|
|
#162799 - 2006-06-21 03:33 PM
Re: loop mapping network drives
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Use Execute() to expand macros or variables that are in strings. For example: Code:
$=Execute('$$aktPath = "$aktPath"')
|
|
Top
|
|
|
|
#162800 - 2006-06-21 03:38 PM
Re: loop mapping network drives
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You can also check for multiple groups by: Code:
If Execute("Exit InGroup($aktGroup)") = 1 ? "Connecting $aktdrive " use $aktdrive "\\"+"$aktpath" EndIf
but check that the quotes (") are still in place in the $aktGroup variable.
|
|
Top
|
|
|
|
#162801 - 2006-06-21 03:41 PM
Re: loop mapping network drives
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Finally, you can enumerate the INI file with something like this: Code:
$inipath = "D:\Tools\KiX\kixlogin.ini" For Each $Counter in Split(ReadProfileString($inipath,"",""),Chr(10)) If $Counter "Section: "+$Counter+@CRLF EndIf Next
|
|
Top
|
|
|
|
#162802 - 2006-06-22 07:55 AM
Re: loop mapping network drives
|
chein
Fresh Scripter
Registered: 2006-06-02
Posts: 8
|
Ah, thank you very much, Richard H.
Just tried the "Execute()" -command. That is what I was searching for. This made both @userid and the group-array work in the loop. I will try the other two suggestions later.
Regards, Carsten
|
|
Top
|
|
|
|
#162803 - 2006-06-22 08:29 AM
Re: loop mapping network drives
|
chein
Fresh Scripter
Registered: 2006-06-02
Posts: 8
|
OK, did work three times in the loop without an error. Now it fails. Wonder if I have changed something...would have been to easy. But I know which command to use/check.
|
|
Top
|
|
|
|
#162804 - 2006-06-22 01:50 PM
Re: loop mapping network drives
|
Pierre FREMION
Getting the hang of it
Registered: 2000-01-11
Posts: 66
Loc: Paris, France, Europe, Sun3
|
Hi Chein
In Kixlogn.kix, just modify the line : $aktGroup = ReadProfileString("$inipath", "$Counter", "Group") in $aktGroup = split(ReadProfileString("$inipath", "$Counter", "Group"),",")
$aktGroup will become an array so the ingroup command will work.
_________________________
Comments always welcome.
French native so I apologize for my (mis)use of English!
|
|
Top
|
|
|
|
#162805 - 2006-06-23 03:41 PM
Re: loop mapping network drives
|
chein
Fresh Scripter
Registered: 2006-06-02
Posts: 8
|
Hello Pierre, thanks for the code.
Just have seen a mistake in my skript, that did not appear whith my test user's membership.
Regards, Carsten
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(mole)
and 1300 anonymous users online.
|
|
|