无法将sessionID 1连接到sessionname控制台,错误代码7045 [英] Could not connect sessionID 1 to sessionname console, Error code 7045

查看:279
本文介绍了无法将sessionID 1连接到sessionname控制台,错误代码7045的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经以交互模式(Windows 10)创建了一个自托管代理计算机,以运行单元测试.在运行自动化测试时断开与远程桌面连接的连接我正在从命令行任务(从Azure DevOps)执行以下命令.当用户登录到代理计算机时,这工作正常.但是如果没有用户登录到该代理计算机,则会出现错误.

I have created a self-hosted agent machine in an interactive mode (Windows 10) to run the unit tests. To disconnect from the Remote Desktop Connections while Running Automated Tests I am executing the below command from a command-line task (from Azure DevOps). This is working fine when the user logged into the agent machine. But getting an error If there is no user logged into that agent machine.

这是预期的行为吗?我们可以绕过这个吗?

Is this expected behavior? Can we bypass this?

%windir%\ System32 \ tscon.exe 1/dest:控制台

错误:

Could not connect sessionID 1 to sessionname console, Error code 7045
Error [7045]: The requested session access is denied.

我尝试了其他选项,例如使用以下代码创建批处理文件并在运行管道时执行它.

I tried with the other options as well like creating a batch file with the below code and executing it while running the pipeline.

这个也有同样的错误

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

推荐答案

命令 query user%USERNAME%将返回会话,即使该用户当前未登录.

Command query user %USERNAME% will return the session even if the user is not currently logged in.

您可以运行命令 query user ^ |.找到活动的" 以仅查询活动的登录用户.

You can run command query user ^| find "Active" to query the active login users only.

参见下文:

for /f "tokens=3" %%s in ('query user ^| find "Active" ') do (
  %windir%\System32\tscon.exe %%s /dest:console 
)

这篇关于无法将sessionID 1连接到sessionname控制台,错误代码7045的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆