请教个问题,在 win10里runas /user:operator cmd后只是拉起了一个operator运行了命令行,如何拉起operator用户的桌面,实现完全切换用户,感谢!
可以理解为写一个 一键切换用户.bat

win通过cmd命令行实现用户切换
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 「已注销」 2023-03-22 15:47关注
参考GPT:要切换到用户的桌面,可以使用Windows提供的 "tscon" 命令。 "tscon" 命令可用于连接到已登录到计算机上的会话。通过连接到用户会话,您可以访问其桌面。
下面是一键切换用户的示例批处理文件(.bat文件):
@echo off rem Replace "username" with the name of the user you want to switch to. set username=username rem Find the session ID of the user you want to switch to. for /f "tokens=3" %%s in ('query user ^| findstr /r /c:"%username%"') do set sessionid=%%s rem Connect to the user's session. tscon %sessionid%
在这个脚本中,您需要将 "username" 替换为您要切换到的用户的名称。脚本使用 "query user" 命令查找与用户名匹配的会话ID,然后使用 "tscon" 命令连接到该会话。要运行此脚本,您需要以管理员身份运行命令提示符窗口。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用