windows调教

断开windows桌面远程连接rdp后,被控制电脑不要自动锁屏

2024-02-18 10:03:50 michael007js 245

断开windows桌面远程连接rdp后,被控制电脑不要自动锁屏

一、可以按照下列步骤,通过让此账号本地登录来断开远程连接,以实现不锁屏的效果:

1.打开记事本,将下列内容复制进去

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (%windir%\System32\tscon.exe %%s /dest:console)

2.然后点按文件-另存为,保存类型改为所有文件

3.然后将文件名改为Logout.bat


当需要以不锁屏的状态断开时,右键保存的Logout.bat,以管理员权限执行,即可断开远程。




二、运行时自动申请以管理员模式运行:

@echo off
REM Check if the script is already running as administrator
net session >nul 2>&1
if %errorlevel% neq 0 (
    REM If not running as administrator, elevate the script
    echo Elevating script to administrator...
    goto UACPrompt
) else (
    REM If already running as administrator, run the command directly
    echo Running the command as administrator...
    for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (%windir%\System32\tscon.exe %%s /dest:console)
    goto :eof
)

:UACPrompt
REM Prompt for UAC elevation
powershell.exe -Command "Start-Process '%0' -Verb RunAs"
exit /b


两个方式核心代码一致,区别只在于申请管理员模式



首页
关于博主
我的博客
搜索