Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Terminal Server Maintenance

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,31330
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Terminal Server Maintenance
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Terminal Server Maintenance - 2/21/2006 1:09:21 AM   
  turranx


Posts: 38
Score: 0
Joined: 2/7/2006
Status: offline
This code was designed to perform a number of behind the scenes tasks to keep our Terminal Server healthy.  At the time this was written, all profiles had a 25,000K storage size limit.  Many users were running past that limit.  One purpose of this script is to empty certian directores within a user's profile of all files and subfolders older than 3 days.  Instructions on how to configure this are below.  The second purpose of this script is to
unload user registry hives from HKEY_USERS (HKU).  Our Terminal Server suffers from a common but hard to diagnose problem where it is unable to unload a users's hive after that user logs off. Perhaps a process is still using that hive when the OS wants to unload it. 

This code relies upon some custom made VBS libraries and one custom made console executable.  I'll be happy to provide both to you if you send me an email at G.Forums@oraucoc.org.

When you put this code into a text file, give it a .WSF extension.

G.


      

_____________________________

Microsoft Windows 2000 Scripting Guide - The best book for newbie scripters
http://www.myspace.com/Evil__Overlord
 
 
Post #: 1
 
 RE: Terminal Server Maintenance - 2/21/2006 2:46:32 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
I am the TS server administrator at my job as well,

I am curious why you developed an in house solution (hiveenum.exe) when there was a MS KB fix for the same thing?

Also, I have yet to run into this problem with the user specific hive not unloading, what happens to the server when this happens and how do you fix it? (other than your script)

Would you please send me your libraries and that console app to the email account listed on my forum account?

Thanks!

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to turranx)
 
 
Post #: 2
 
 RE: Terminal Server Maintenance - 2/21/2006 2:51:59 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I have a few comments.
1) I think some more indentation would make the code more legible.
2) It is well commented.
3) It appears to be using some library functions which you have not posted. That makes this code very hard to be adapted to someone else's environment.(Disregard)
4) It looks like you use several arrays to keep track of the folders to search and information on how to process those folders. I would lean toward a dictionary to do this.
5) Do While True Loop constructs are dangerous IMO and run the risk of wasting resources.
6) I think the use of a global On Error Resume Next statement is dangerous in that it would mask errors that you really should correct.

As always, these comments are purely my opinion and since you have a script that does what you need, then by definition it is written correctly.

< Message edited by ebgreen -- 2/21/2006 3:40:15 AM >


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to turranx)
 
 
Revisions: 1 | Post #: 3
 
 RE: Terminal Server Maintenance - 2/21/2006 3:36:26 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
quote:

ORIGINAL: ebgreen
3) It appears to be using some library functions which you have not posted. That makes this code very hard to be adapted to someone else's environment.


Their original post stated that they would send the libraries and the custom console app via email if required. I have requested them since I'd like to take a look at them.

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: Terminal Server Maintenance - 2/21/2006 3:38:31 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ehh...reading comrehension is overated. 

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Post #: 5
 
 RE: Terminal Server Maintenance - 2/21/2006 5:10:04 AM   
  turranx


Posts: 38
Score: 0
Joined: 2/7/2006
Status: offline
HiveEnum.exe is a safer way of obtaining a list of user registry hives than installing the hotfix.  This particular hotfix wasn't regression tested.  It's not likely to become an official patch, nor find it's way into Win2000 SP5 (if there ever is such a thing).  Our development/test TS doesn't suffer from this inability to unload user registry hives, so I couldn't test the hotfix there.  Stability of our TS is a major concern of ours and I hesitate to install an untested hotfix on our production TS. 

Description of Terminal Server behavior pre-script
The production TS would occasionally display "Out of Registry Space" errors, then inform us it was automatically increasing our registry size.  After a week of uptime (from a reboot), the TS became unstable.  Users would attempt to log in but would receive one of two results: either the login attempt would "freeze" before the user was presented with a desktop, or they would be presented with a generic Guest desktop and receive a message that their registry hive could not be loaded.

Furthermore, attempts to map to \\Terminal_Server\c$ would fail.  The Terminal Services Manager utility I keep on my desktop couldn't connect to our TS. 

I had started to think there was a memory leak, so I installed poolmon.exe on our TS and began watching TS like a hawk.  Below are some outputs from poolmon.exe. 
-------------------------------------------------------------------------------------------------------

Memory: 7601392K Avail: 6611496K  PageFlts:  6629   InRam Krnl: 3292K P:109316K
Commit:1072056K Limit:19690960K Peak:2092960K            Pool N:44512K P:109508
Tag  Type     Allocs            Frees            Diff   Bytes      Per Alloc

CM   Paged    175897 (  15)    164321 (  14)    11576 51532512 (    32)   4451
MmSt Paged    348435 (  47)    339941 (  92)     8494 14709856 (-127744)   1731
SavE Nonp    5224418 ( 901)   5223987 ( 901)      431 13320160 (     0)  30905



---------------------------------------------------------------------------------------------------------
System Up Time: 13D 20H
Problem: Zero available System Page

Memory: 7601392K Avail: 6009760K  PageFlts:  4538   InRam Krnl: 3192K P:170636K
Commit:1731088K Limit:19690960K Peak:3100648K            Pool N:30240K P:170920
Tag  Type     Allocs            Frees            Diff   Bytes      Per Alloc

CM   Paged   1704824 (   4)   1680881 (   4)    23943 107688384 (     0)   4497
RadS Paged 317650747 (1453) 317647866 (1453)     2881 28105376 (     0)   9755
MmSt Paged  11506291 (  73)  11502628 (  63)     3663 6899872 ( 25920)   1883



It wasn't until I installed the 'Debugging Tools for Windows' and read C:\Program Files\Debugging Tools for Windows\triage\pooltag.txt that I found out CM = Configuration Manager (registry).  I thought CM = Cache Manager from all the reading I did on Microsoft.com.  Once I learned the CM process handled the registry, I inspected HKEY_USERS and found many registry hives were loaded for users that weren't currently using the TS. The 'RadS' tag is for the Symantec Antivirus Corporate Edition service.


How I handled the problem without the script
I translated the name of each hive into a userID using GetSID.exe from www.sysinternals.com and made sure that user wansn't logged on.  If they weren't logged on to the TS, I'd unload their hive using regedt32.exe.   This was a long and drawn out task perfect for automating.  As I did this, the Paged Kernel Memory (as is visible in the Performance Tab of Windows Task Manager) would drop from 170000 down to 120000 and responsiveness, connectivity, and user's ablity to log into TS would return to normal.


Alternate Solution
There is a 3rd party utility you can download from Microsoft called UPHClean: http://www.microsoft.com/downloads/details.aspx?FamilyID=1b286e6d-8912-4e18-b570-42470e2f3582&displaylang=en&Hash=SY534SC .  Our resident TS expert installed UPHClean on our Test TS, but was unable to make it work properly.  It was for this reason I automated the task.


Response to EBGreen
Arrays I tend to use a lot.  You're probably right about Dictionaries; I should use them.  I just haven't taken the time to learn them.  :)

My indentation habbits sometimes swing between tabbing (8 spaces) or just 1 space.  It depends on the kind of mood I'm in when I write the script.

I made sure that any objects I instantiated were also destroyed at the end of the loop.  Of course, if you find one that I've missed, I'll correct my code.

I've become so used to writing code with On Error Resume Next and writing my own error handling routines, that I usually only enable On Error Goto 0  when I'm debugging.  It might seem backwards, but it works for me. :) 


The only reason I won't post the libraries is because I want to know who's reading/running/using my code.  I'm interested in who's interested in my vbs babble.

G.

_____________________________

Microsoft Windows 2000 Scripting Guide - The best book for newbie scripters
http://www.myspace.com/Evil__Overlord

(in reply to kirrilian)
 
 
Post #: 6
 
 RE: Terminal Server Maintenance - 2/21/2006 5:47:12 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
quote:

I made sure that any objects I instantiated were also destroyed at the end of the loop.  Of course, if you find one that I've missed, I'll correct my code.


I wasn't concerned with object clean up. Garbage collection has become much better in recent releases of WSH. I was more concerned with the general implications of running an infinite loop. This script looks like it will essentially run constantly forever. I would tink that would be a processor ineficient implementation that's all.

EDIT: Spelling.

< Message edited by ebgreen -- 2/23/2006 1:00:20 AM >


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to turranx)
 
 
Revisions: 1 | Post #: 7
 
 RE: Terminal Server Maintenance - 2/22/2006 3:52:30 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
thank you so much for your history and information on why you wrote this script. we are running 2003 on our TS server and have yet to run across this problem, so perhaps they fixed this problem in TS for 2003 but who knows. Our next step as our user base grows is to run a TS server farm with multiple nodes using the built in load balancing for TS, that should be interesting!



_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Terminal Server Maintenance Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts