Created
October 3, 2014 17:44
-
-
Save davidruhmann/b8dd00f8877489771eb5 to your computer and use it in GitHub Desktop.
SO26181747.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: usage: script.bat [username=%username%] | |
call :AnyActiveRemoteSessions %~1 %username% && echo Yes || echo No | |
exit /b 0 | |
:AnyActiveRemoteSessions [Username] | |
for /f "skip=1 tokens=2,4" %%A in ('query user %~1 ^| find ">"') do call :IsActiveRemoteSession "%%~A" "%%~B" && exit /b 0 | |
exit /b 1 | |
:IsActiveRemoteSession <Session> <State> | |
if /i "%~2"=="active" echo "%~1" | find /i "rdp-tcp" && exit /b 0 | |
exit /b 1 | |
:: OP's structure | |
for /f "skip=1 tokens=2,4" %%A in ('query user %username%') do ( | |
if /i "%%~B"=="active" echo "%%~A" | find /i "rdp-tcp" >nul && echo RDP: Yes || echo RDP: No | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment