WTSQuerySessionInformation 有时会失败并显示“访问被拒绝”

发布于 2024-10-20 19:34:19 字数 780 浏览 1 评论 0原文

我使用以下 API 调用来确定远程的名称终端服务器会话中的客户端:

ret = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, 
                                 WTS_INFO_CLASS.WTSClientName, buffer, bufferLen)

通常,当应用程序未在终端服务器会话中运行时,调用会成功 (ret != 0),并且 buffer 仅返回 null指针。所以我认为这是预期的行为。

然而,在一位客户的计算机上,该函数开始失败 (ret == 0),并且 GetLastError 返回 5:访问被拒绝。 (与往常一样,客户声称他的系统配置没有以任何方式更改。)

因此,我的问题如下:

  • 在非终端服务上查询 WTSClientName 时的预期行为是什么?机器(例如“常规”Windows 7 PC)?
  • 返回此错误代码的原因可能是什么?请注意,在我们的测试机器上,即使用户没有管理权限,函数调用也始终按预期运行(成功且缓冲区为空)。

我不知道这是否相关,但我们可以通过从 Web 应用程序内部调用该函数来重现此问题(错误 5)。然而,本例中的情况并非如此(它是常规 Windows 应用程序)。

I'm using the following API call to determine the name of the remote client in a Terminal Server session:

ret = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, 
                                 WTS_INFO_CLASS.WTSClientName, buffer, bufferLen)

Usually, when the application is not running in a terminal server session, the call succeeds (ret != 0) and buffer just returns a null pointer. So I figured that this was the expected behavior.

On one customer's machine, however, the function started to fail (ret == 0) and GetLastError returns 5: Access Denied. (As usual, the customer claims that his system configuration did not change in any way.)

So, my questions are the following:

  • What is the expected behavior when querying the WTSClientName on a non-terminal-services machine (such as, e.g., a "regular" Windows 7 PC)?
  • What could be the reason that this error code is returned? Note that, on our test machines, the function call always behaves as expected (success and empty buffer), even if the user does not have administrative rights.

I don't know if this is relevant, but we are able to reproduce this problem (error 5) by calling the function from inside a web application. This, however, is not the case in this case (it's a regular Windows application).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

む无字情书 2024-10-27 19:34:19

我同意你的观点,并且还认为客户端的一些系统配置已更改。要找出文件系统或注册表中的更改中的哪一项对于 WTSQuerySessionInformation 很重要,您可以尝试使用 进程监视器

您还可以要求您的客户下载该工具,启动 Process Monitor,然后启动您使用 WTSQuerySessionInformation 的测试程序,保存日志并将其发布给您。我想,您会在日志中看到一些“访问被拒绝”错误。我希望它能帮助您找到客户端计算机配置中的问题。

I agree with you and also suppose that some from system configuration at the client are changed. To find out which one from the changes in file system or in registry are important for WTSQuerySessionInformation you can try to use Process Monitor.

You can also ask your customer to download the tool, start the Process Monitor and then start your test program used WTSQuerySessionInformation, save the log and post it to you. I suppose, that you will see some "access denied" errors in the log. I hope it will help you to find the problem in the configuration of the client's computer.

眼趣 2024-10-27 19:34:19

我不知道预期的行为,但在 Win7 上调用 WTSEnumerateSessions 时遇到错误代码 5,访问被拒绝。将 DWORD HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\AllowRemoteRPC 设置为 1,问题立即得到解决。

I don't know the expected behavior but I encountered error code 5, access denied, when calling WTSEnumerateSessions on Win7. Set DWORD HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\AllowRemoteRPC to 1 and issue was immediately fixed.

蓝色星空 2024-10-27 19:34:19

当您从 Web 应用程序调用它时,就会发生这种情况,因为 Web 服务器正在 Windows 的(会话 0)下运行。

了解更多关于会话0

This is happening when you call it from web application becasue the web server is running under the (session 0) of windows.

read more about session 0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文