Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


Return to article

PsExec to the Rescue
 

In my previous position, I sometimes had to grant temporary access to remote servers to the administrators of other departments in that company. Sometimes these administrators forgot to log off the remote server after they completed their tasks, thus locking out other administrators when the Windows Server 2003 Terminal Services session limit had been reached. Usually the offending administrators were out to lunch or had left for the day. This always seemed to happen when there was a problem that needed immediate attention on that server. Typically, I had used Terminal Services Manager to log off the administrator. However, there were times when that wasn’t an option because the remote server I needed to access was the one running Terminal Services Manager.

When I was searching the Internet for a solution to this problem, I came across a discussion of the PsExec tool in the Windows Power Tools column “PsExec” (July 2004, InstantDoc ID 42919). PsExec lets you launch interactive command-prompt sessions and run programs on remote systems without having to install client software on those systems. This tool looked promising, so I downloaded the latest version from the Microsoft TechNet website (technet.micro soft.com/en-us/sysinternals/bb897553.aspx).

I decided to try PsExec in a test environment. I ran a command that followed the syntax

C:\psexec \\ServerName
  -u Domain\UserID cmd
where ServerName was the name of the remote server I needed to access and Domain UserID was the username I wanted to use to log on to that server. The cmd argument told PsExec to launch an interactive command-prompt session on that server.

After I entered my password, the remote server’s command-prompt window appeared. I then ran the Query Session command:

Query Session
The output showed the user IDs of the administrators who were connected to the server. I was then able to use the following Logoff commands with the administrators’ IDs to log off those administrators:
Logoff 2
Logoff 3
Afterward, I reran the Query Session command to see if those administrators were logged off. The Logoff commands were successful.

Because this was a test environment, I knew that the administrators I logged off weren’t running any important tasks on the remote server. However, in a production environment, you need to make sure that the administrator you’re about to log off isn’t running an important task. You can use the Tasklist command to check which tasks are running and who is running them. Assuming you’re still logged on to the remote server, you can use the command

Tasklist /v /fi "STATUS eq running"
From that point on, I used PsExec to log off administrators on all remote servers. Using Terminal Services Manager to access a remote server takes a couple of minutes, whereas using PsExec takes only a couple of seconds. As this practical usage of PsExec demonstrates, sometimes you need to keep an open mind and think beyond GUIs.

—Tim Bolton, Microsoft infrastructure technician, Lightedge Consulting Services







Reader Comments

Good article TIm. One more reason to "Let the ways of the command prompt", and since TS is still a big part of our life I hope you cover other non GUI ways to negate the errors of the "carbon units". Curt Spanburgh

SCG -October 03, 2008

Great article Tim. Thanks for sharing this gem. Congrats on the first of many I'm sure.

MrEclipseguy -October 04, 2008

psexec is a valuable tool but for the above tasks it is not necessary. builtin tools, such as tskill.exe and logoff.exe both supports remote logoff. Murat Yildirimoglu

muraty -October 07, 2008

Great. I have many more examples of the amazing and talented psexec at work. I should document them some time.

netmarcos,netmarcos -October 08, 2008
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement