Skip to content

Instantly share code, notes, and snippets.

@red-avtovo
Created October 13, 2017 23:03
Show Gist options
  • Save red-avtovo/b144d034adafbadb652ff4505a132264 to your computer and use it in GitHub Desktop.
Save red-avtovo/b144d034adafbadb652ff4505a132264 to your computer and use it in GitHub Desktop.
Kick all rdp clients from Win Server
Dim serverName
serverName = InputBox("Server name to look sessions in","Server name prompt")
rem MsgBox(serverName)
Set oShell = WScript.CreateObject("WScript.shell")
rem qwinsta /server:server
Set oResult = oShell.Exec ("qwinsta /server:"&serverName)
strText = StrConv(oResult.StdOut.ReadAll(), "ibm866", "windows-1251")
Function StrConv(Text, SourceCharset, DestCharset)
Set Stream = CreateObject("ADODB.Stream")
Stream.Type = 2
Stream.Mode = 3
Stream.Open
Stream.Charset=DestCharset
Stream.WriteText Text
Stream.Position = 0
Stream.Charset=SourceCharset
StrConv = Stream.ReadText
End Function
If (serverName<>"") Then
Dim id
id = InputBox(strText & vbNewLine & "Choose id to kick","Id prompt")
If (id<>"") Then
rem rwinsta if /server:server
oShell.Exec ("rwinsta " & id & " /server:" & serverName)
End If
End If
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment