|
Querying and Dropping Windows Terminal Service Sessions Remotely
I often run into scenarios where I can't access a server via Terminal Services because there are no available sessions. This usually means there are too many people signed on, or one or more sessions have hung in a disconnected state. So how do you check? You connect (via TS) to another server and utilize the following utilities.
This will list users that are on the server whose IP you provide, as well as the state of their connection >QWINSTA /server:1.1.1.1 This will give you the ability to drop a user given their session ID
>RWINSTA /server:1111
Pretty neat. Thanks Scott Forsyth I use this feature a lot, so I figured I'd post it.
Killing processes remotely (using RKILL) This is a neat tool that will allow you to list process ID's on a remote machine (that you were an ADMINSTRATOR of), and kill processes on the remote machine - as the name suggests a la *nix style. You can downlaod this tool from here. Usage is simple.
C:\tools>rkill Usage : rkill /view \\servername to get the process list on servername Usage : rkill /kill \\servername pid to kill process pid on servername Usage : rkill /token \\servername to get your remote security token on servername Usage : rkill /install \\servername to install the RemoteKill service on servername Usage : rkill /deinstall \\servername to deinstall the RemoteKill service on servername
To install RKILL remotely: C:\tools>rkill /install \\yourServerName
To obtain a token: C:\tools>rkill /token \\yourServerName
To view processes: C:\tools>rkill /View \\yourServerName [Outputs Processes and PID's]
To kill a process: C:\tools>rkill /kill \\yourServerName 123
Lastly, a VBS script to get the randomly generated IUSER_MACHINENAME account from your box in case you lock yourself out (oops!)
'Script will find default password for IUSER_MachineName account 'This pw is randomly generated by win
Function outputTextFile(pString) 'Function creates text file for debug Dim objFileSystem, objOutputFile, strOutputFile 'generate a filename base on the script name strOutputFile = "./" & Split(WScript.ScriptName, ".")(0) & ".out" Set objFileSystem = CreateObject("Scripting.fileSystemObject") Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE) objOutputFile.WriteLine pString objOutputFile.Close Set objFileSystem = Nothing End Function
Dim IIsObject Set IIsObject = GetObject ("IIS://localhost/w3svc") 'WScript.Echo "According to the metabase, the anonymous credentials are:" 'WScript.Echo " AnonymousUserName = " & IIsObject.Get("AnonymousUserName") 'WScript.Echo " AnonymousUserPass = " & IIsObject.Get("AnonymousUserPass") 'WScript.Echo " WAMUserName = " & IIsObject.Get("WAMUserName") 'WScript.Echo " WAMUserPass = " & IIsObject.Get("WAMUserPass")
outputTextFile(IIsObject.Get("AnonymousUserPass")) Set IIsObject = Nothing
|