Tuesday, December 21, 2010

Configuring ICA / RDP session timeout values using WMI VB script

Many times you may want to use a script to configure a Windows Server RDP or the Citrix ICA timeout values.  Although these can be achieved using a Group Policy Object (GPO) if your computers are in an Active Directory domain, you may choose to use a script such as this to set the timeout values in certain situations.  For example, before the computers are joined to a domain, or on computers running Terminal Services or Citrix that are not managed by a GPO.


Here I share the VBS codes to achieve this.  There are 3 timeout values you can set:


  1. Active Session Timeout
  2. Idle Session Timeout
  3. Disconnected Session Timeout




Active Session Timeout - this value determines when to disconnect the session from the user, while the session is still alive on a server, even if the user is actively working on the session


Idle Session Timeout - this value determines when to disconnect the session from the user if the user does not perform any activities (via keyboard and mouse) on the session


Disconnected Session Timeout - this value determines when a disconnected session - a session that is running on a server but are not presented to a user - will be terminated on a server




The lines of code below are not optimized.  I just did a quick-and-dirty approach to achieve what I want to do.  You will need to modify it to make it do what you want to set.


The functions will also check if the GPO has enforced the values.  This means it will not be able to set the value if so.  There are no detail comments on what the functions are.


If you have suggestions to make this better please feel free to leave comments.


This script can be run using cscript.exe.



'This script supports Windows XP/Server2003/Vista/Server 2008 only.  Windows 2000 is not supported
'
'Your should run this script with the //b parameter for running in auto-admin script to suppress console output
'
'This script can be duplicated for step-outs if required and just change the values of the timeout
'


Option Explicit
Dim ICAActiveSessionTimeout,ICAIdleSessionTimeout,ICADisconnectedSessionTimeout
Dim RDPActiveSessionTimeout,RDPIdleSessionTimeout,RDPDisconnectedSessionTimeout
Dim strOSversion,iResult
Dim objWMI_TS,strComputer




'==========================================================
' MAIN BODY STARTS
'==========================================================
ICAActiveSessionTimeout = 0                                     ' A 0 means never timeout
ICAIdleSessionTimeout = 1800000                                            ' 30 mins in milliseconds
ICADisconnectedSessionTimeout = 28800000      ' 8 hours in milliseconds


RDPActiveSessionTimeout = 0                                    ' Never
RDPIdleSessionTimeout = 600000                                             ' 10 mins in milliseconds
RDPDisconnectedSessionTimeout = 900000                         ' 15 mins in milliseconds


strComputer = "."    ' if a computer name can be specified here if you have remote administrative rights to it




strOSVersion = OSVersion()
WScript.echo "OS Version is: " & strOSVersion


If strComp(strOSVersion,"6.0",1) > 0 Then
' If this is Windows Server Vista/Server 2008


  WScript.Echo "This is a Vista/WS2K8 or newer"
  Set objWMI_TS = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2\TerminalServices")
  iResult = ConfigureTSSessionWS2K8("ICA-tcp",ICAActiveSessionTimeout,ICAIdleSessionTimeout,ICADisconnectedSessionTimeout)
  iResult = ConfigureTSSessionWS2K8("RDP-Tcp",RDPActiveSessionTimeout,RDPIdleSessionTimeout,RDPDisconnectedSessionTimeout)
  iResult = ConfigureTSClientSettingWS2K8("RDP-Tcp")


Elseif strComp(strOSVersion,"5.2",1) >0 Then
' If this is XP/Server 2003


  WScript.Echo "This is an XP/Server 2003"
  Set objWMI_TS = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  iResult = ConfigureTSSession("ICA-tcp",ICAActiveSessionTimeout,ICAIdleSessionTimeout,ICADisconnectedSessionTimeout)
  iResult = ConfigureTSSession("RDP-Tcp",RDPActiveSessionTimeout,RDPIdleSessionTimeout,RDPDisconnectedSessionTimeout)


Else


  WScript.Echo "This operating system is not supported."
  WScript.Quit(0)


End If


WScript.Echo ""
WScript.Echo "Result of the action: "
DisplayTSSessionSetting


WScript.Quit(0)


'==========================================================
' MAIN BODY ENDS
'==========================================================






'-----------------------------------------------------
' FUNCTIONS AND SUBROUTINES
'-----------------------------------------------------


Function ConfigureTSClientSettingWS2K8(strTerminalName)
'
' This configures the Printer Mapping property
'
Dim colItems,objItem,errResult,objInstances,objInstance,iResult


  Set colItems = objWMI_TS.ExecQuery("Select * from Win32_TSClientSetting WHERE TerminalName='" & strTerminalName & "'")


  If NOT IsNull(colItems) Then
    For each objItem in colItems
      WScript.Echo ">Configuring Client Settings for " & objItem.TerminalName
      WScript.echo " Configuring Windows Printer Mapping"
      Wscript.Echo "  Current setting: " & objItem.WindowsPrinterMapping
      if objItem.PolicySourceWindowsPrinterMapping = 1 Then
        WScript.Echo "  Cannot change WindowsPrinterMapping because of enforced GPO"
      else
        iResult = objItem.SetClientProperty("WindowsPrinterMapping",1)
      End If
      objItem.Put_
      Wscript.Echo "  New setting: " & objItem.WindowsPrinterMapping
    Next
  End If


End Function






'-----------------------------------------------------
'
'This works on Windows Server 2008/Vista only
'
Function ConfigureTSSessionWS2K8(strTerminalName,ActiveSessionTimeout,IdleSessionTimeout,DisconnectedSessionTimeout)


Dim colItems,objItem,errResult


  Set colItems = objWMI_TS.ExecQuery("Select * from Win32_TSSessionSetting WHERE TerminalName='" & strTerminalName & "'")


  if NOT IsNull(colItems) Then
    For Each objItem in colItems
        WScript.echo ">Setting " & objItem.TerminalName


        If UCase(objItem.TerminalName) = UCase(strTerminalName) Then
           objItem.TimeLimitPolicy = 0
           objItem.put_


                   If objItem.PolicySourceActiveSessionLimit <> 1 Then
              errResult = objItem.TimeLimit("ActiveSessionLimit",ActiveSessionTimeout)
           Else
              WScript.Echo "Policy enforced.  Cannot set ActiveSessionLimit"
           End If


           If objItem.PolicySourceIdleSessionLimit <> 1 Then
              errResult = objItem.TimeLimit("IdleSessionLimit",IdleSessionTimeout)
           Else
              WScript.Echo "Policy enforced.  Cannot set IdleSessionLimit"
           End If


           If objItem.PolicySourceDisconnectedSessionLimit <> 1 Then
              errResult = objItem.TimeLimit("DisconnectedSessionLimit",DisconnectedSessionTimeout)
           Else
              WScript.Echo "Policy enforced.  Cannot set DisconnectedSessionLimit"
           End If


           objItem.refresh_
        End if
    Next
  End If


  ConfigureTSSessionWS2K8 = 0


End Function
'-----------------------------------------------------




'-----------------------------------------------------
'
'This function is for Windows XP/Server 2003 only
'
Function ConfigureTSSession(strTerminalName,ActiveSessionTimeout,IdleSessionTimeout,DisconnectedSessionTimeout)


Dim colItems,objItem,errResult


  On Error Resume Next


  Set colItems = objWMI_TS.ExecQuery("Select * from Win32_TSSessionSetting WHERE TerminalName='" & strTerminalName & "'")


  if NOT IsNull(colItems) Then
    For Each objItem in colItems
        WScript.echo ">Setting " & objItem.TerminalName


        If UCase(objItem.TerminalName) = UCase(strTerminalName) Then
           objItem.TimeLimitPolicy = 0
           objItem.put_


           errResult = objItem.TimeLimit("ActiveSessionLimit",ActiveSessionTimeout)
           errResult = objItem.TimeLimit("IdleSessionLimit",IdleSessionTimeout)
           errResult = objItem.TimeLimit("DisconnectedSessionLimit",DisconnectedSessionTimeout)
           objItem.refresh_
        End if
    Next
  End If


  ConfigureTSSession = 0


End Function


'-----------------------------------------------------


'-----------------------------------------------------
'
'Displays the session values
'
Sub DisplayTSSessionSetting


Dim objInstances,objInstance


  Set objInstances = objWMI_TS.InstancesOf("Win32_TSSessionSetting",48)


  For Each objInstance in objInstances
     WScript.Echo objInstance.getObjectText_
  Next
End Sub
'-----------------------------------------------------




'-----------------------------------------------------
'
'Query the OS version number
'
Function OSVersion()
Dim objOS
  OSVersion = 0
  On Error Resume Next


' Connect to WMI and obtain instances of Win32_OperatingSystem
  For Each objOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")


    OSVersion = objOS.Version


  Next


  if Err <> 0 Then
      WScript.Echo "ERROR in function OSVersion(): " & Err.Description
      Err.Clear
  End if
End Function
'-----------------------------------------------------

Monday, December 20, 2010

5 things I do not like about the Nissan Grand Livina (1.8L review)

The Nissan Grand Livina - a mini MPV that - according to Nissan Malaysia, "Drives like a sedan, fits like an MPV".  I agree that the car was easy to drive around, and the ride comfort is excellent.  Being seated in the car on the front passenger seat does not remind of my experience in a bigger MPV like the Toyota Innova, which was similar to being in a van as I could feel my seat sway left and right when travelling 90km/h on a straight line.






The Nissan Grand Livina







The Nissan Grand Livina




But the Grand Livina does have many things, mostly in the car interior, that I feel Nissan could have easily adjust to improve and make the cusomters happy. Here I list the 10 things I disklike about the Nissan Grand Livina.





1) The primitive audio System

The moment I sat in the car, I can immediately see the very dull-looking audio system.  The buttons are big but they only serve a single function at all time.  This Clarion does not play any MP3, WMA, or USB contents.  And it does not have any AUX input.  The speakers, however, are pretty nice with enough clarity to listen to.




Simple audio system with a single Audio CD player and radio (No MP3, No USB)


2) The noisy air-conditioning system

There are 4 speeds available on the air-conditioner.  The lowest speed is quiet, but I can hardly feel the wind even when seated on either the driver or the front passenger seat.  The middle aircond vents take some getting used to to adjust and you really need to fine-tune it carefully to direct the wind.  On a cool day, this level is sometimes nice.  On a hot day, at least a level 2 is needed to make the cabin more comfortable.  Level 2 gives you stronger wind, however, it also creates more noises in the cabin.  Level 3 or 4 shoud only be used for a short period when you just want to 'turbo' the fan in response to passengers complaints.

Oh and note that there are only 3 positions in the air cond flow paths on the knob (compared with 5 positions normally).

What, only 3 positiosn on the direction control?  Even a MyVi has 5.  Note that the windscreen vent is not available
That's right. No holes on the 'vent' under the windscreen

3) The irritating safety seat belt

I was so disappointed to realize that the seat belt on the front seats cannot be height-adjustable!  I think such design only exists in the 1980's, when I saw often during my taxi rides in an old Nissan Sunny.

So the problem with this is that the belt does make me feel very uncomfortable.  The belt rubs against my neck and shoulder too often during ride, causing irritating skin rashes.  I had to use a belt clip to loosen it but doing this will reduce the effectiveness of a safety belt.



Non-height adujustable seat belt!  This will be first in my not-to-buy checklist when shopping for cars in the future


4) Narrow opening angle of the back doors

Being an MPV, I think the back doors should open wider.  A wide-opening door (like what the MyVI has, or the new Honda City) not only gives enough space for people to move in/out quickly, but it also makes loading cargoes through the doors an easier feat.

This is as wide as it can open

5) Lack of convenient storages for the driver

The car has 1 glove box too deep for the driver, one covered storage (on a 1.8l model) under the cockpit, one door pocket, one small storage on the door which also serves as a door handle, one center storage placed with the hand brake.

Where are the cup holders?  They are combined with the covered storage under the cockpit.  If you have a water bottle, you lose your storage to store small notes, sunglasses, receipts, ...

The glove box is deep, and its door cover has a strange design where there are openings on both side where the hinges are.  Small items will drop off, or get in the way between the hinges to close the door.




The covered storage. Looks OK so far









A cup holder and an ashtray





The cup holder tray with the ashtray can be removed, which gives you more space.  But you'll lost cup holder on the front
The cup holder tray with the removable ashtray



Deep glove box.  Openings on the sides for items to fall off


The center storage where the hand brake is








Driver side door pocket and door handle/storage.  A Touch N Go Smart Tag will most likely be stored here


Door pocket on the back door.  Narrow - enough to fit small thin items only

Price of this car: RM 97,300 OTR
I have more to complain but I'll leave this for now.  Until next time.  Do drive safely!

Tesco LED headlight pictures and descriptions

I found this LED headlight (model: TL-9588) at Tesco the other day.  This is the headlight you wear on your head (not for your car, heh).  This piece of device is useful when you need a directional light beam while freeing up both your hands to work on something in a dim area, or to look under your car bonnet.  Well, there are many applications.  You can use it while searching deep into your wardrobe for that piece of t-shirt, working on the screws in your desktop computer tower, searching your storeroom boxes for that old PC game CDs, walking down the stairs at night during power failure, ...


The price was about less than RM20 at Tesco when I bought it in August 2010.


This LED lamp has 4 modes: Off, On-High, On-Low, On-Flashing


The angle of the beam is 90-degree adjustable and it uses 3 x AAA battery.




Pretty useful LED lamp I would say!  Keep one in your car too.  And this thing has a flash mode, which is useful to warn any incoming traffic at night.

Sunday, December 19, 2010

Persimmon price RM10 for 8 pieces

This box of persimmons was RM10 in the morning market at Taman Midah today.  They are sweet!

Cheras Rehabilitation Hospital (Hospital Rehabilitasi Cheras) construction progress pictures

Have a look at the consturction.  These pictures show the hospital under construction, from most recent to the least recent.  The last photo at the bottom of this post shows the original site with trees.  The completion date is set to be in 4Q 2011.  This center would focus on post-hospitalisation rehabilitation.

UPDATED PHOTO - 01-MAR-2011 @ 7.35pm

01 Mar 2011 @ 7.35pm


OLDER PHOTOS from here on

19 Dec 2010 6am

18 Dec 2010 11am

18 Dec 2010 11am

19 Dec 2010 11am



7 July 2009


7 July 2009


7 July 2009


7 July 2009


4 Nov 2008




4 Nov 2008



4 Nov 2008


   
6 Apr 2008

6 Apr 2008

14 Jan 2007
 

Friday, December 17, 2010

XBOX 360 Slim versus XBOX 360 - a pictorial comparison

If you want to know how the XBOX 360 S (slim) compares with the older version of XBOX 360, here are some pictures to show.  The black one is the S (version) of the XBOX 360.

The XBOX 360 Slim is much quieter than the older version, but I don't think it's 'whisper quiet' as Microsoft has been claiming.  The DVD drive does make some, if not equal to the older version, amount of noise when it spins up.  But the internal fans are bigger and thus are quieter, that's a fact.

Original XBOX 360 and the XBOX 360 Slim
The XBOX 360 Slim is shorter in length, and thinner in width

The depth is almost similar though - XBOX 360 vs. XBOX 360 Slim

The smaller power adapter is definitely welcome!  It saves space and is lighter and easier to carry around.

XBOX 360 Slim power adapter is smaller and light

One fact about cockroaches

"If a cockroach loses its head for some reason, it can still live for weeks before starving to death. The cockroach's head can live for a few hours on its own, too. It will live longer if it is fed."


Ewww...I hate cockroaches!

Thursday, December 16, 2010

Alcoholic - Joke

A joke I got in my email:

In an alcohol factory the regular taster died and the director started looking for a new one to hire.

A drunkard with ragged, dirty look came to apply for the position.
The director of the factory wondered how to send him away.
They tested him.

They gave him a glass with a drink. He tried it and said,

"It’s red wine, a muscat, three years old, grown on a north slope, matured in steel containers."
"That’s correct", said the boss.

Another glass.


"It’s red wine , Cabernet, eight years old, a southwestern slope, oak barrels."
"Correct."

The director was astonished.


He winked at his secretary to suggest something.


She brought in a glass of urine. The alcoholic tried it.

"It’s a blond, 26 years old, pregnant in the third month.
And if you don’t give me the job, I’ll also tell who’s the father!"

Wednesday, December 15, 2010

The only Digital Lifestyle Expo (DLE) 2010 Photo I took


All the way from South Korea, here is the "special girls" appearance.  Oh they do know how to pose!

“勇”字

汉字字源
这是“智勇双全”中的“勇”字,本为会意兼形声的字。①是金文的写法。上部为“戈”,下部为“用”。“用”亦表音,意谓 “用戈者,勇也”。②是《说文》中古文的写法,上部讹变为“甬”,下部为“心”,可见“勇”与“心”有关。③是小篆的形体,“心”又变为“力”,说明 “力”是“勇”的基础。④是楷书的写法。
Source: zdic.net