Tuesday, September 29, 2009

Remote Logoff terminal sessions:

How to logoff remote desktop sessions via command line tools?

This trick I learned from my one of ex-college. In Windows servers, only two remote desktop sessions allowed with administrative access. There are situations, you can't connect to the server via remote desktop because of two sessions already active. You may have seen this dialog box. ("Remote Desktop Disconnected", "This computer can't connect to the remote computer")

Usually Windows Administrators, open "Terminal Services Manager" (in Administrative tools), connect to the problematic server and log off the unwanted sessions. There are easy ways if you love command line based tools.

Query the Remote Server for Current Terminal Sessions

To query and list the sessions on the remote session, you could use QUser.exe or QWinsta

1. QUser

QUser command comes with all the latest Windows clients and servers. This will list the sessions of the remote server (or local machine).

NOTE: if you are using Windows XP, you need to add this location into your System path: C:\Windows\System32\DLLCache. To do this, in command prompt, type the following.

SET PATH = %PATH%;C:\Windows\System32\DLLCache;

QUser help shows,

C:\Anand>QUser /?
Display information about users logged on to the system.

QUERY USER [username | sessionname | sessionid] [/SERVER:servername]

username Identifies the username.
sessionname Identifies the session named sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).


C:\>quser /server:MyCitrixSVR
johndoe ica-tcp#966 10 Active 7 7/31/2008 3:04 PM
averagejoe ica-tcp#969 1 Active 9 7/31/2008 3:30 PM
familyman ica-tcp#984 5 Active 1:06 7/31/2008 4:33 PM
normaldude ica-tcp#987 2 Active 4 7/31/2008 6:20 PM

2. QWinsta

QWinsta is little different and better. It has more features and options. It comes with all flavors of Windows. QWinsta command line help displays as,

C:\>qwinsta /?
Display information about Terminal Sessions.

QUERY SESSION [sessionname | username | sessionid]
[/SERVER:servername] [/MODE] [/FLOW] [/CONNECT] [/COUNTER]

sessionname Identifies the session named sessionname.
username Identifies the session with user username.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).
/MODE Display current line settings.
/FLOW Display current flow control settings.
/CONNECT Display current connect settings.
/COUNTER Display current Terminal Services counters information.


C:\>qwinsta /server:citrixserver
0 Disc rdpwd
ica-tcp 65536 Listen wdica
rdp-tcp 65537 Listen rdpwd
console 16 Conn wdcon
ica-tcp#966 johndoe 10 Active wdica
ica-tcp#969 apple 1 Active wdica
ica-tcp#984 averagejoe 5 Active wdica
ica-tcp#987 familyman 2 Active wdica
ica-tcp#989 whoisme 3 Active wdica

You are welcome to try the other options QWinsta provides.

Logoff the Remote Sessions

To Log off the terminal session of the remote server, you can use any one of two command line tools. One of LOGOFF and another one is RWINSTA. Before you log off the remote session, you should know the "Session ID" which you get it from "QUSER" OR "QWINSTA" commands as above stated.

1. Logoff

Logoff command kicks off (logging off) the specified remote session. Log off help shows,

C:\>logoff /?
Terminates a session.

LOGOFF [sessionname | sessionid] [/SERVER:servername] [/V]

sessionname The name of the session.
sessionid The ID of the session.
/SERVER:servername Specifies the Terminal server containing the user
session to log off (default is current).
/V Displays information about the actions performed.


C:\>logoff /server:infra-apps 1 /v
Logging off session ID 1

2. RWinsta

RWinsta has same parameters and does same thing as log off command. It simply means Reset WINdows STAtion. The help goes as,

C:\>RWinsta /?
Reset the session subsytem hardware and software to known initial values.

RESET SESSION {sessionname | sessionid} [/SERVER:servername] [/V]

sessionname Identifies the session with name sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server containing the session (default is current).
/V Display additional information.


C:\>RWinsta /Server:MyWinServer 1

Note: RWinsta command does not return anything.

Happy Re-setting the remote sessions (Hey, stop cursing your co-workers who didn't log off their sessions).

Keywords: Reset remote session, Remote Desktop Session

Wednesday, August 26, 2009

Setting up Privoxy on Windows Server 2003

1) Install Privoxy
What is Privoxy? Privoxy is a non-caching web proxy with advanced filtering capabilities for enhancing privacy, modifying web page data and HTTP headers, controlling access, and removing ads and other obnoxious Internet junk. Privoxy has a flexible configuration and can be customized to suit individual needs and tastes. It has application for both stand-alone systems and multi-user networks.

2) Setup a Privoxy User account and add it to the Local Administrators group to allow Privoxy to run as a service.

3) Set Default Domain Group Policy to disallow local-login for the service account and allow Log on as a service.

4) Set Privoxy as a service


5) Configure the Privoxy service to run as the Privoxy user

6) Set the Privoxy service as Automatic and set Recovery to restart the service if fails after one minute.

7) Create three new Organizational Units called “Full Internet Access” “Limited Internet Access” and “No Internet Access” and move the users into their proper organizational units.

8) Under Limited Internet Access, create a Group Policy called “IE Proxy Limited” and within that policy, uncheck “Use the same proxy for all addresses”, check “Enable proxy settings”, and in the “Address of proxy” set it to the server’s IP address for HTTP and Secure. Change the port to 8118 for those two.

In addition, within that group policy set “Disable changing proxy settings” to Enabled:

9) Under the “No Internet Access”, create a Group Policy called “IE Proxy No Internet” and within that policy, uncheck “Use the same proxy for all addresses”, check “Enable proxy settings”, and in the “Address of proxy” set it to IP address for HTTP and Secure. Ensure to also set “Disable changing proxy settings to “Enabled”.

10) Remove the comment on "trustfile"

10) Finally add the following to the Privoxy “Trust List” and you're all done! :)

Friday, April 03, 2009

How to Print from the command line

Classexec is an amazing *and free* program. This line should do it:

"classExec.exe" "C:\Documents and Settings\ttye\test.xls" --action printto "HP Universal Printing PS" --ifexec

That line will print Excel documents from a command line to a specific printer.

The "HP Universal Printing PS" is the Printer Name.

Download it here:

Thursday, January 29, 2009

Creating a bootable USB key with Syslinux and VistaPE

1) Format your USB key under VISTA or VISTAPE using diskpart:
select disk 1
create partition primary size=
select partition 1
format fs=fat32

2) Save the boot sector using Bart's mkbt.exe program. This is done on the command prompt using:
mkbt.exe -x -c E: E:\VISTABT.bs

Where E: is your USB drive.

3) Use Syslinux to install the syslinux bootsector. Download syslinux and then from the win32 folder execute the following:
syslinux -ma E:

Where E: is your USB drive.

-ma == update master boot record and make the partition active

You should now have a bootable SYSLINUX USB key. From here you can create a file on the root of your USB key called syslinux.cfg and enter the following:

#serial 0 19200
default boot
display boot.msg
timeout 250
prompt 1

label boot
kernel VISTABT.bs

When you enter "boot" you will boot the Vista boot sector. From here you can add Peter's NTPasswordChg and other linux utilities without having to use Grub4DOS or any others.