Showing posts with label PS4. Show all posts
Showing posts with label PS4. Show all posts

Friday, July 13, 2007

MFCOM: Connection licenses and usage count

Yet Another Citrix Administrator Task, monitor the connection licenses and usage count in the farm...

Feel like a hill billy...

Code Snippet:

  1. Dim fso
  2. Set fso = CreateObject("Scripting.FileSystemObject")
  3. If not fso.FolderExists("c:\liclog" ) then
  4. Set MyFolder = fso.createFolder("c:\liclog" )
  5. else
  6. End if
  7. if not fso.FileExists("c:\liclog\licCount.log" ) then
  8. Set MyFile= fso.createTextFile("c:\liclog\licCount.log")
  9. MyFile.writeline "Date " & " Time " & "Lic Type " & "Used"
  10. MyFile.close
  11. else
  12. end if
  13. Const ForAppending = 8
  14. Set MyFile= fso.OpenTextFile("c:\liclog\licCount.log", ForAppending,True)
  15. Dim theFarm, aLicense
  16. Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
  17. ' Initialize the farm object.
  18. theFarm.Initialize(MetaFrameWinFarmObject)
  19. For Each aLicense In theFarm.LicenseSets(MFLIcenseClassConnection)
  20. if aLicense.LicenseID = "0000000000000003" then
  21. MyFile.WriteLine date & "," & time & "," & aLicense.Name & "," & aLicense.pooledinuse("")
  22. else
  23. end if
  24. next
  25. MyFile.Close


If at first you fail, call it version 1.0

Monday, July 09, 2007

KD Memory.dmp debugging

One of our Citrix server encountered a BSOD, luckily we had RSA and managed to hard reboot the server.

I've gathered the memory dump to view the cause of BSOD and found the Symantec Antivirus has caused a module error on the NIC driver.

We have then disabled the Network Drives in the File System Auto Protect and it had not experienced the same ever since.

Did not find any help from Symantec regarding the root cause other than it's a known issue.

Below are some steps that you could use for debbuging:

  1. Launch windbg passing it the location of the symbol files, the source files (i386 directory) and the dump file. Example: windbg -y dump\symbols -i SRC\i386 -z dump\Memory.dmp

  2. At the bottom of the Command window there is a kd> prompt.

  3. The commands are entered into that prompt: kd>!analyze -v

  4. Two things to look for in the results: the memory referenced and the FAULTING_IP

  5. The command: kd>lm - will produce a listing of modules and their memory location.

  6. Look to see which module's memory the memory referenced identified above falls in.

  7. That usually indicates the process that caused the crashed and will probably match the FAULTING_IP if listed.

  8. Also informative: kd>.reload –v

If at first you fail, call it version 1.0

Wednesday, June 13, 2007

String manipulation in NT scripts

I was working on a Citrix Login script and found out most clients are not able to perform WMI queries to get session information from the server or just simple evironment variable expansion... or is it just our GPO is just too tight?

Instead of using vbscript for the string manipulation, I opted to the old school NT scripting, since the built in usrlogon script in PS4 is native to NT.

So I searched the help files and the net for old DOS commands for string manipulation as my goal for this script is to get the first 2 characters from the environment variable %CLIENTNAME%. If the machine name's first 2 characters are "UK", then a certain drive is required to be mapped.

Now, It is possible to retrieve specific characters from a string variable.

Syntax:
%variable:~num_chars_to_skip%
%variable:~num_chars_to_skip,num_chars_to_keep%

This can include negative numbers:
%variable:~num_chars_to_skip, -num_chars_to_skip%
%variable:~-num_chars_to_skip,num_chars_to_keep%

A negative number will count backwards from the end of the string. In Windows NT 4 the syntax for negative numbers was not supported.

Examples:
The variable _test is used for all the following examples:

SET _test=123456789abcdef0

::Extract only the first 5 characters

SET _result=%_test:~0,5%
ECHO %_result% =12345

::Skip 7 characters and then extract the next 5

SET _result=%_test:~7,5%
ECHO %_result% =89abc

::Skip 7 characters and then extract everything else

SET _result=%_test:~7%
ECHO %_result% =89abcdef0

::Extract only the last 7 characters

SET _result=%_test:~-7%
ECHO %_result% =abcdef0

::Extract everything BUT the last 7 characters

SET _result=%_test:~0,-7%
ECHO %_result% =123456789

::Extract between 7 from the front and 5 from the end

SET _result=%_test:~7,-5%
ECHO %_result% =89ab

::Go back 7 from the end then extract 5 towards the end

SET _result=%_test:~-7,5%
ECHO %_result% =abcde

::Extract between 7 from the end and 5 from the end

SET _result=%_test:~-7,-5%
ECHO %_result% =ab

And this is the final script:
SET _CNAME=%CLIENTNAME%
CALL SET _ORIGIN=%_CNAME:~-0,2%

IF %_ORIGIN% EQU UK (
NET USE R: \\UKFILSERVER\CITRIX$
) ELSE (
GOTO Done
)

:Done

If at first you fail, call it version 1.0