Sunteți pe pagina 1din 6

Hel

#bout Us

Me8ber Lo"in

#S:

#NSW,R

*OP$CS

#R*$CL,S

*U*OR$#LS

<LOGS

S*#R* =R,, *R$#L

Search E perts E chan!e


E perts E chan!e "emote #ccess Citri $o% &S"'()(*+C,- Processin! .or/s

How USRLOGON.CMD ro!essin" works


Status Published

#$D% #$D% &'() &'()

*o Citri+ ,+ erts
Week Month ;ear Overall
Overall

2,970 POINTS

-.

Mutawadi Wi2ard 0 points yesterday

('./.01

Coralon
Type: Tutorial Posted on: 2012-01-17 at 14:47:06

'. (.

CarlWebster dkotte basra4 Coralon sekar!3u *on6-.33 $ts7#7v*ra 4oharder

'-./&.1 -)&/&(' -3(/35) -'5/')' -'5/-.. 03/5'' ))/0&( )3/&.) )(/&0) (-/1&' ''/3)( '-/5.. -&/.5' -5/5&. -)/(-) -)/'1) -3/5)1 -./10. &/01&/'(. 5/(). 0/&.. 0/0.. 0/-00

The usrlogon.cmd process is a hold-over from the Windows NT 4.0 TSE days, ut it is still a very useful mechanism for running user level scripts - it is especially useful when a !"# is not availa le. What is it:
Link

3. ). 1. 0. 5. &.

This is a script the is launched as part of the user logon process. $t is standard in every Terminal Services%&emote 'es(top Services installation. The script has several parts that serve different purposes, from home directory mappings to e)ternal scripts provided y the administrator. The script e)ists in *systemroot*+system,-, and is denoted y the e)tension, it is a plain te)t atch file. The script is launched from the registry. The launch point is ./01+Software+1icrosoft+Windows NT+2urrent3ersion+Win0ogon. 'epending on the TS%&'S version, usrlogon.cmd will e part of the 4ppSetup value or the 5ser$nit value. Script breakdown: The first step of the script is
1: Call "%SystemRoot%\Application Compatibility Scripts\SetPaths.Cmd" Print

-.. han!!o!ka --. el!huru -'. sar8ah4a6 -(. ts8v -3. robin!8 -). 8attv8otas -1. dbor"er -0. n sin"h-'( -5. barr6k9l -&. 4vr..1 '.. eduardoa"uirrev '-. MrGraves

This step launches the Set"aths.cmd atch file and waits for it to return. Setpaths.cmd is a script that uses the acregl.e)e utility to e)tract common program paths and set that information in Environment varia les. 6$t is a several step process in and of itself, ut it is effectively outside of the scope of this article7. The (ey fact is that this step will set an environment varia le called 8Set"aths as either S522EE' or 94$0. The second step of this script is to chec( the status of the first step. $f it fails, it will e)it, if it succeeds, it will continue. The iggest issue is that the Set"aths step will very fre:uently fail and over years of e)perience has een proven highly ;unrelia le;. $f you do not write your application compatibility scripts using those varia les from Set"aths.cmd, then it is perfectly safe to simply comment out the -nd step. $ do this y adding - < mar(s at the eginning of the line.
1: ::If "%_S !PA!"S%" ## "$AI%" &oto 'one

''. LeeOsborneU: '(. :r#2; '3. #da8<N;C '). 2oubi00

The third step loo(s to see if is a file called *systemroot*+system,-+usrlogn=.cmd 61ore on this file later7< $f it is there, go to *systemroot*+application compa itility scripts+logon and e)ecute it. #nce the usrlogn=.cmd file and it>s child process are complete, the script continues.

$f the usrlogn=.cmd file doesn>t e)ist, then the script changes into the *systemroot*+application compati ility scripts? directory and then e)ecutes the rootdrv.cmd file. 6This is an important step7. This har(ens ac( to those NT 4 TSE days. 0n those days1 %hen user2s home directory %as speci3ied in the directory1 it %ould connect the user to the directory as the speci3ied home directory+ The issue %as that in 4most4 en5ironments1 a top le5el directory %ould be shared out that contained the user directories+ So1 i3 dri5e &: %as mapped to the home directory1 it %ould connect as u<+username because the actual directory %as ++server+share+username+ 0n those days1 there %as 3re6uently a need to con3i!ure applications to point to a uni6ue directory 3or a user 3or lon! term stora!e1 con3i!uration in3ormation1 etc+ Since .indo%s %as !enerally a sin!le interactive user operatin! system1 the applications !enerally ne5er e pected to ha5e multiple interacti5e users connected at the same time and didn2t ta/e their application con3i!urations into consideration+ 7re6uently1 the applications %ould simply store their user con3i!uration in3ormation in the $8E9:'(C#':,#C$0*E re!istry hi5e because it %as a ;con5enient; %ay to ma/e it accessible to all the users o3 a machine+ Combinin! all o3 these elements %as a challen!e in the *T4 TSE en5ironment+

The reason this is important is to esta lish a drive letter that is the same for all the users, ut points to a uni:ue path. This is called the &oot 'rive. This ne)t step changes from the *systemroot*+application compati ility scripts+logon directory to the *systemroot*+application compati ility scripts directory and tries to e)ecute the &oot'rv.cmd command. &oot'rv.cmd gets e)ecuted - it chec(s for the e)istence of the &oot'rv-.cmd and e)ecutes if it e)ists. @y default, &oot'rv-.cmd does not e)ist. RootDrv2.cmd sets an environment varia le RootDrive e:ual to the intended drive letter. The su se:uent step chec(s for an environment varia le called &oot'rive that gets created y &oot'rv.cmd. $f the environment varia le does not e)ist, then the script e)its and runs the end.cmd file which simply echoes a lan( line. $f the administrator desires, special cleanup routines can e run from end.cmd, although $ have never seen it used. &oot'rv-.cmd is created y the administrator e)ecuting the script *systemroot*+application compati ility files+ch(root.cmd. 2h(&oot.cmd tries to e)ecute rootdrv.cmd, and if the &##T'&$3E does not e)ist, then ch(root.cmd echos the script lines into &oot'rv-.cmd and opens the file in notepad and waits for the administrator to enter in the appropriate varia le. The script lines are all comments e)cept for one<
1: set rootdri(e#

. The comments e)plain what to put there. 9or e)ample<


1: set rootdri(e#h:

Chkroot.cmd then tries to e)ecute rootdrv-.cmd again, and if it still fails, it will set an environment varia le 82./&##T to 94$0 and changes into the *systemroot*+application compati ility scripts+install directory. $f it does ;not; fail, then it e)ecutes the usrlogon.cmd file and when usrlogon.cmd completes, it will write the &oot'rive value to the registry under ./01+Software+1icrosoft+Windows NT+Terminal Server (ey. Now that the &oot'rive varia le is set, usrlogon.cmd uses the value of &##T'&$3E to create a drive letter that is the same for all users, ut points to a uni:ue location. The ?magic? of this is the old S5@ST command. This creates a drive letter that points to a specific path.

The command is
1: s)bst %rootdri(e% %homedri(e%%homepath%

9or e)ample< $f the user>s home drive is u<+ and the home path is username, and the &##T'&$3E is set to .<, then the command is su st .< 5<+username. So, effectively, all of the users on the system will have an .< ut there home directories are uni:ue. The e act steps are - the script attempts to delete the "((T-"0<E letter as a mapped dri5e and chec/s to see i3 it still e ists+ 03 it does1 then it deletes it as a substitute =S&>ST? dri5e+ Now that a uni:ue drive letter is esta lished, the script goes on to e)ecute usrlogn-.cmd and when completed it e)its. &emem er the usrlogn=.cmd $ mentioned a ove, and now the usrlogn-.cmd scriptsA The intent of usrlogn=.cmd is to e)ecute scripts in *systemroot*+application compati ility scripts+logon. The intent of usrlogn-.cmd is to e)ecute scripts in *systemroot*Bapplication compati ility scripts+logon that re:uire a uni:ue drive letter. Neither of these scripts e)ist y default -- they must e created y an administrator. These scripts should e create in *systemroot*+system,-. The usrlogon.cmd script e)pects them to e there, and they will not e used if located somewhere else.

Now that the asic mechanics are e)plained, we can go over how this can e used, why it can e a good idea to use it, and interesting tid its a out it. How it can be used: 4s the directory name shows, it is for 4pplication 2ompati ility Scripts 6although you can do anything with it7. The idea is that these scripts will run and configure whatever needs to e done for an application. Some e)amples are settings specific environment varia les, copying files, adding registry entries, or Cust a out any activity that a user could do that can e scripted. To this end, 1icrosoft provides some utilities in *systemroot*+application compati ility scripts that are not well documented, ut they are useful. $f you search for them on TechNet you can find the documentation for them. http<%%support.microsoft.com%( %=DE F-E%r acregl.exe - this is used y the ch(root script, ut this utility loo(s up a registry value and creates a atch file to create an environment varia le that contains the registry value data. acsr.exe - this is ;very; fast te)t search and replace. Typically, this would e used to change a value in a file as the user logs in - for e)ample, ta(ing a aseline configuration file and creating a copy in the user>s home directory containing uni:ue values for the user. aciniupd.exe - this utility can update $N$ files. This was especially useful for dealing with =F it Windows applications that were heavily $N$ driven. Wh it can be used: $n this day and age, these mechanics are infre:uently used. The prevailing standard operatin! method is to use !roup "olicy and other methods of deploying scripts. .owever, sometimes these mechanics will rea( down, or may simply not e availa le. #r you may want these scripts to affect your administrators, and they are not affected y the !"#>s.. there are other scenarios, these are Cust the more common ones. !nteresting tidbits: These are cmd files and y default, these windows are visi le to the logging on user and can e e)ited y them. The 1icrosoft way to deal with this is to use a !"# to configure legacy logon scripts to run silently. This wor(s great. The 2itri) way is to use a utility called ct)hide.e)e that was created several years ago to

launch the cmd file 6usrlogon.cmd7 silently. $n fact the 2itri) installations will automatically detect the usrlogon.cmd launch point in the registry and modify them to include ct)hide.e)e. 6So, usrlogon.cmd ecomes ct)hide.e)e usrlogon.cmd7. The pro lem is that ct)hide.e)e has een riddled with pro lems and fre:uently the command to e launched 6in our case, usrlogon.cmd7 simply never gets launched. To avoid this, $ simply remove the ct)hide.e)e reference from the registry. #ne thing $ have seen on occasion is people modifying the usrlogon.cmd to e)ecute code, or putting scripting code directly into the usrlogn=.cmd or usrlogn-.cmd. While this does technically wor(, the intention is for these scripts to call ;other; scripts. $n fact, the original *systemroot*+application compati ility scripts+install directory used to contain scripts to wor( around some (nown issues with e)isting 1icrosoft applications. Gou would run these install scripts, and they would create scripts in the *systemroot*+application compati ility scripts+logon directory and automatically place a statement to run them in the usrlogn=.cmd or usrlogn-.cmd file. @ecause of this, it was very important to ma(e sure your modifications to these files ended with a lan( line. #therwise, an automated script might Cust tac( itself on to the very end of the script line and create an unwor(a le command. When creating scripts to use for usrlogn=.cmd or usrlogn-.cmd e aware of some (ey facts. =. Gour scripts can change directories, ut they should return to the initial directory 6*systemroot*+application compati ility scripts+logon7. 6They can do this with the pushd and popd commands. "ushd will change into the specified directory and remem er where is started from. "opd will return to the directory stored y pushd. "ushd can accept a 5N2 path - it will simply map the first availa le drive wor(ing ac(wards from H< and then change the directory7. -. Gou will typically want to >call> a su -script. 5sing 2400 instructs the atch file to launch the process and wait for it to return. ,. 4s an alternate, if you don>t need to wait for the su -script to return, you can use ST4&T. ST4&T will launch the process and continue on immediately. 4. 'on>t use EI$T in your su -scripts. This will e)it the cmd.e)e process that launched with usrlogon.cmd and su se:uently stop the processing of any other su -scripts. J. Gou can launch powershell scripts with these mechanics. Kust use powershell.e)e -file LfilepathM -nologo -noninteractive -noprofile F. This entire process runs in the user>s security conte)tN 'on>t put things in there that the user could not do.

=0F /@

usrlogon processing flow%diagram

*a"s% Citri+, >en# *o i!% Citri+ ?iews% -,4EJ

, N* 3.. *S,, Presentation Server, Meta=ra8e Server

#bout *he #uthor


Coralon
Coralon has been %or/in! %ith Citri products since .in7rame 1+@ and is an e pert %ith the 3amily o3 products and other related technolo!ies+

More #rti!les =ro8 Coralon

Co88ents
AUTHOR COMMENT
y< 2oralon on -0=--0--0, at ==<,F<=0 $'< 4=EDD

ump, hoping to get this >released> <-7 2oralon

AUTHOR COMMENT
y< 2oralon on -0=--0--0D at =D<4,<-- $'< 4-,EJ

Than( you.. $ did try to rea( it up, ut $>ll see what $ can do to clean it up more. 2oralon

EXPERT COMMENT
y< reredo( on -0=--04-0- at ==<--<4J $'< 4DF0F

great. e)actly what we>re loo(ing for th)OO

#dd 6our Co88ent


"lease Sign up or 0og in to comment on this article.

WHAT IS EXPERTS EXCHANGE?


Overview How it works =eatures ?iew *o i!s Plans @ Pri!in" Our Custo8ers

OUR COMMUNITY
Point S6ste8 ,+ ert <ene9its <usiness #!!ounts Custo8er Su ort Aob <oard

GET SUPPORT
Site Hel Su ort Center *er8s o9 Use Priva!6 Poli!6 Site Ma URL Shortener

THE COMPANY
#bout Us Conta!t Us <lo" *e!h News <lo" ,, Store

MAIN TOPICS
Mi!roso9t # le $nternet Ga8ers Di"ital Livin" ?irus @ S 6ware Hardware So9tware Se!urit6 Pro"ra88in"

<rowse #ll *o i!s Develo er Stora"e OS Database

TRENDING TOPICS
iOS AavaS!ri t MS #!!ess Aava MS SDL Server #ndroid ?isual <asi! .N,* MS ,+!el ,+!han"e CE Outlook PHP WordPress Ora!le Database ?isual <asi! Classi! .N,* Pro"ra88in"

Web Develo 8ent Networkin"

Mobile Site

B -&&1C'.-' ,+ erts ,+!han"e/ LLC. #ll ri"hts reserved.

S-ar putea să vă placă și