Skip to content

Instantly share code, notes, and snippets.

@gioxx
Created March 7, 2016 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gioxx/ff0f741e00942bcd6c8d to your computer and use it in GitHub Desktop.
Save gioxx/ff0f741e00942bcd6c8d to your computer and use it in GitHub Desktop.
Permette di disconnettere tutte le sessioni RDP avviate su un server, oppure di disconnetterne solo una, specificandola da prompt dei comandi. Vedi articolo originale: http://gioxx.org/2016/02/19/rdp-remote-logoff/
@echo off
REM RDP Remote Logoff
REM GSolone - ult.mod. 07032016
REM utilizzo: RDPLogoff.cmd NOMESERVER
REM ATTENZIONE: va utilizzato come amministratore locale o di dominio della macchina alla quale si punta
IF "%1" == "" GOTO DatiMancanti
IF "%2" NEQ "" GOTO SingoloDisconnetti
cls
echo Disconnetto tutti gli utenti da %1 ...
if not exist C:\temp mkdir C:\temp
quser /server:%1 >C:\temp\session.txt
for /f "skip=1 tokens=3," %%i in (C:\temp\session.txt) DO logoff /server:%1 /v %%i
del C:\temp\session.txt
goto END
:SingoloDisconnetti
cls
echo Disconnessione di %2 da %1 ...
if not exist C:\temp mkdir C:\temp
quser %2 /server:%1 >C:\temp\session.txt
for /f "skip=1 tokens=3," %%i in (C:\temp\session.txt) DO logoff /server:%1 /v %%i
del C:\temp\session.txt
goto END
:DatiMancanti
echo.
echo ATTENZIONE
echo Server o utente da disconnettere non specificato.
echo Rilancia lo script con i giusti parametri.
echo.
:END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment