#201549 - 2011-02-10 01:02 AM
Use numbers from %logonserver%
|
newjackswinger
Fresh Scripter
Registered: 2011-02-02
Posts: 6
Loc: Australia
|
Hey guys,
This is my first post on this forum, hope I am posting in the right section.
My question is:
Is it possible to extract numbers from %logonserver% and use those numbers to map network drives?
Situation is as follows:
I have roaming users on a school network. Depending on what school they are at, will depend on what network drives I would like mapped. I have decided that the best unique identifier would be their logonserver. Each school has a domain controller and a file/print server. The first few digits of the logonserver are the same digits on the FNP server.
So what I would like is something like the following:
%logonserver% = 1234DC01
I would like to use the 1234 in the example above to map drives: use M: \\1234fnp01\data
If the logonserver has 5 digits e.g. 12345, I would like to use that also.
I want to avoid doing the following: IF %logonserver% = 1234dc01 use m: \\1234fnp01\data IF %logonserver% = 13456 use m: \\13456\data
Reason being is that they have close to 100 domain controllers and the script will not look very nice and probably take a while to run. I would like to just query the logonserver for the numbers I need and map drives based on that.
Hope I am clear in the description...
Thanks in advance...
|
|
Top
|
|
|
|
#201552 - 2011-02-10 02:39 AM
Re: Use numbers from %logonserver%
[Re: Allen]
|
newjackswinger
Fresh Scripter
Registered: 2011-02-02
Posts: 6
Loc: Australia
|
Hi Glenn,
Sorry whereabouts on your site can I find the script you are referring to?
Allen, I will give your code a go.
We have AD Sites and Services configured with all the subnets available. If someone doesn't authenticate with their local DC, then we may have an issue and we will know about it and resolve it.
Thanks for replies...
|
|
Top
|
|
|
|
#201556 - 2011-02-10 08:57 AM
Re: Use numbers from %logonserver%
[Re: newjackswinger]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If you just want the numeric prefix you can go very simple:
$sServerPfx=Val(%LOGONSERVER%)
USE M: "\\" + $sServerPfx + "fnp01\data"
|
|
Top
|
|
|
|
#201565 - 2011-02-11 04:04 AM
Re: Use numbers from %logonserver%
[Re: Glenn Barnas]
|
newjackswinger
Fresh Scripter
Registered: 2011-02-02
Posts: 6
Loc: Australia
|
Hi Richard and Allen,
I have tried to use your code and have been unsuccessful. I am using Kix 4.53.
I literally copied and paste your code into the script and it has not mapped. I am getting the right logonserver, access to the network share is working. Drive just won't auto map. I can map network drives by using IF INGROUP, use m: etc etc....
Any ideas?
|
|
Top
|
|
|
|
#201568 - 2011-02-11 10:18 AM
Re: Use numbers from %logonserver%
[Re: Allen]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
And check for the failure reason:
$sServerPfx=Val(%LOGONSERVER%)
USE M: "\\" + $sServerPfx + "fnp01\data"
If @ERROR "*FAILED* to map M: to \\" + $sServerPfx + "fnp01\data - Reason: ["+@ERROR+"] "+@SERROR+@CRLF EndIf
|
|
Top
|
|
|
|
#201577 - 2011-02-14 01:26 AM
Re: Use numbers from %logonserver%
[Re: Richard H.]
|
newjackswinger
Fresh Scripter
Registered: 2011-02-02
Posts: 6
Loc: Australia
|
Hey guys,
Please excuse my ignorance. I am only familiar with the basic kix commands. I have tried the above and did not see any errors punched out?
Below are my basic scripts (without any of the code above put it). I am using 7777 as unique identifier for server.
My logonserver is 7777DCC01. I wish to use the 7777 from the logonserver to map drives to the FNP server
====================================================== 7777.bat
@ECHO OFF %logonserver%\netlogon\software\wkix32.exe %logonserver%\netlogon\7777\7777.kix /i ====================================================== 7777.kix
; 7777.KIX ; KiXtart script to map network drives
$SERVER = '7777FNP01' $DOMAIN = 'DOMAIN.LOCAL'
; ******** Map Network Drives ********
use i: /delete /persistent use g: /delete /persistent use m: /delete /persistent use s: /delete /persistent
SLEEP 1 ======================================================
Thank you for your assistance and patience.
|
|
Top
|
|
|
|
#201578 - 2011-02-14 02:18 AM
Re: Use numbers from %logonserver%
[Re: newjackswinger]
|
lukeod
Getting the hang of it
Registered: 2008-01-11
Posts: 70
Loc: Australia
|
A few things i'll add:
1) I find it's best not to statically reference the name of the server you are running the script from. You can use relative paths instead. Why this is useful is because if the name of the server changes, or you are running the script from another location, it will still work. For example, if its a multi-DC environment and you are storing the scripts in the NETLOGON share (SYSVOL), this will replicate between domain controllers.
So to do this, you would be best to place the batch file and kix script in the same directory and use:
%0\..\wkix32.exe %0\..\7777.kix /i
The "%0\.." bit is basically just saying 'in the same directory as the batch file'.
However that's not really critical, it just causes less headaches in the long run.
As for the script, a few pointers.
2) There is two reasons you aren't getting errors. > Firstly, you are using wkix32 instead of kix32. wkix is the same as kix32 except it suppreses console output, so you will not see console output. For testing, kix32.exe is in my opinion, the better choice, once happy with it swap to wkix32.exe > Secondly, kix only outputs error messages by default if there is a syntax error. The way you get error information is by telling the script you want it. For example:
use i: /delete /persistent
? "ERROR CODE = " + @ERROR
? "Verbose error description = " + @SERROR
@ERROR typically returns an integer, corresponding to (i think) typical windows error codes, such as '0' for successful. These are good for checking as conditions in loops, if/else/endif statements etc.
@SERROR typically returns a string, such as 'The operation has been succesful'
Without knowing the exact setup at your site it's difficult to know for sure, but this is possibly close to what you want:
<disclaimer> : I havn't tested this at all, use at own risk, do own testing etc if it breaks your computer, not my fault!! </disclaimer>
; 7777.KIX
; KiXtart script to map network drives
;Variables
;Get the hostname of the server that served the logon request
;IE this should be the local domain controller, if in a domain environment
$strLogonServer = @LSERVER
;Get the domain name, rather than declaring it explicitly.
;This way script wont break if domain renamed or something
$strDomain = @DOMAIN
;Determine the Site Code.
;Do this by making the variable $strSiteCode equal to the
;first 4 characters of the $strLogonServer variable
$strSiteCode = Left($strLogonServer,4)
;Lets build a site-specific string equal to the name of the file server\share
$strSomeFileShare = "\\" + $strSiteCode + "FNP01\SomeShare"
;Delete some mappings, display error codes.
; This would really be best as a function, but best to keep it simple
; while learning
use i: /delete /persistent
? "i: - Error (" + @error + ") SERROR(" + @SERROR + ")"
use g: /delete /persistent
? "g: - Error (" + @error + ") SERROR(" + @SERROR + ")"
use m: /delete /persistent
? "m: - Error (" + @error + ") SERROR(" + @SERROR + ")"
use s: /delete /persistent
? "s: - Error (" + @error + ") SERROR(" + @SERROR + ")"
;Presumably you will want to map a drive(s). lets map it to z:\
mapdrive($strSomeFileShare, "z:")
;To prevent the script from closing the second
;it has completed, and thereby not giving
;us a chance to see the output, we can tell it to
;wait for the user to press a key before continuing/closing
;This should be removed before production, but handy for testing
Get $
;---------------------
;Function to Map a Drive
;---------------------
Function mapdrive($drivepath, $driveletter)
Use $driveletter $drivepath
If @ERROR = 0
? "Drive: " $drivepath " was mapped successfully"
Else
? "Drive ( " + $drivepath + " ) was NOT mapped!"
? "Error: " + @SERROR
EndIf
EndFunction
Edited by lukeod (2011-02-14 02:31 AM)
|
|
Top
|
|
|
|
#201579 - 2011-02-14 05:00 PM
Re: Use numbers from %logonserver%
[Re: lukeod]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
I think I realize the error. Val(%logonserver%) will not work due to the "\\" at the beginning. Try using this instead when you need to get the server number...
$servernumber = Val(Split(%logonserver%,"\\")[1])
$server = "\\"+$servernumber+"FNP01"
You can then use the new $server variable further down to map your drives. For example...
Use i: $server+"\sharename"
|
|
Top
|
|
|
|
#201605 - 2011-02-16 04:28 AM
Re: Use numbers from %logonserver%
[Re: ShaneEP]
|
newjackswinger
Fresh Scripter
Registered: 2011-02-02
Posts: 6
Loc: Australia
|
Hey CitrixMan,
That code works perfectly. I tried it on three different servers with different server numbers (some had 4 and some had 5) and the drives mapped correctly. Thanks, much appreciated.
What would happen if the logonserver doesn't have any numeric values i.e. OFFDC01 rather than 7777DC01, will the script just fail or continue to process?
Thanks heaps everyone for your help...
|
|
Top
|
|
|
|
#201606 - 2011-02-16 04:38 AM
Re: Use numbers from %logonserver%
[Re: newjackswinger]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Any portion that uses that $server variable will more than likely not work.
What the Val() function does int he first line is tries to get the numerical value of the %logonserver%. It stops when it reaches the first non numeric character, and will simply return a 0 if non are encountered...so in the case of OFFDC01, the $server variable will become '0FNP01' instead of something like '7777FNP01'.
You could add an IF statement before the segment of the script that uses the $server variable to ensure it was set correctly first...For example...
IF Len($servernumber)>1
net use i: $server+"\sharename"
net use j: $server+"\sharename"
etc...
EndIf
|
|
Top
|
|
|
|
#201607 - 2011-02-16 04:42 AM
Re: Use numbers from %logonserver%
[Re: ShaneEP]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
You could also add an alternative when the $server is initially set...example...
$servernumber = Val(Split(%logonserver%,"\\")[1])
if $servernumber>0
$server = "\\"+$servernumber+"FNP01"
else
$server = %logonserver%
endif
|
|
Top
|
|
|
|
#201609 - 2011-02-16 05:58 AM
Re: Use numbers from %logonserver%
[Re: Allen]
|
newjackswinger
Fresh Scripter
Registered: 2011-02-02
Posts: 6
Loc: Australia
|
Awesome, thanks guys for the help...
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 584 anonymous users online.
|
|
|