WTSQueryUserToken 失败,getlasterror() 返回 1723

发布于 2024-08-11 14:09:26 字数 6927 浏览 3 评论 0原文

我有一个在系统帐户的凭据下运行的 Windows 服务。该服务定期轮询窗口以获取活动控制台会话 ID,即交互式登录的 Windows 用户,然后通过 pinvoking wtsapi32.dll 函数 WTSQueryUserToken(…) 检索与活动控制台会话 ID 关联的用户令牌。此实施在现场 99.9% 的时间里都能完美运行。然而最近,我发现一位客户的实施会定期(但从不始终如一)无法检索活动控制台会话 ID 的用户令牌。

请参阅本文底部的客户操作系统信息。

当 WTSQueryUserToken() 失败时,GetLastError() 返回 Windows 系统错误代码 1723。

错误代码 1723 的描述:“RPC 服务器太忙,无法完成此操作”

以下是演示实现的示例代码片段:

int ActiveSession = 0;
Win32Wrapper.GetActiveConsoleSessionId(ref ActiveSession);
IntPtr UserToken = IntPtr.Zero;

if(!Win32Wrapper.WTSQueryUserToken(ActiveSession, ref UserToken))
{
   int myErr = Convert.ToInt32(Win32Wrapper.GetLastError());
   log("Failed to retrieve UserToken." + myErr.ToString());
   return;
}
else
{
   log("Retrieved User Token");
}

有谁知道可能会发生什么?是罪魁祸首吗?

以下是客户的设置:

  • 身份验证:Active Directory
  • 操作系统:
  • Microsoft Windows NT 5.1.2600 Service
  • Pack 3 当前 UI 区域性:en-US
  • 当前区域性:en-US CLR
  • 版本:2.0.50727.3603
  • IE 版本:8.0.6001.18702
  • 系统类型:32位可用
  • 物理内存:411MB 总
  • 物理内存:893MB 系统
  • 制造商:Dell Inc.
  • 型号:Vostro 1000
  • 处理器 1:AMD Athlon(tm) 64 X2 双核处理器 TK-57

服务:

名称:Alerter 启动模式:禁用 状态:已停止 名称:应用层网关服务 启动方式:手动 状态:运行 名称:苹果移动设备 启动模式:自动 状态:运行 名称:应用管理 启动方式:手动 状态:已停止 名称:ASP.NET 状态服务 启动方式:手动 状态:已停止 名称:Ati HotKey 轮询器 启动模式:自动 状态:运行 名称: Windows 音频 启动模式:自动 状态:运行 名称:后台智能传输服务 启动模式:自动 状态:运行 名称: 卓悦服务 启动模式:自动 状态:运行 名称: 电脑浏览器 启动模式:自动 状态:运行 名称:索引服务 启动方式:手动 状态:已停止 名称: 剪贴簿 启动模式:禁用 状态:已停止 名称:.NET运行时优化服务v2.0.50727_X86 启动方式:手动 状态:已停止 名称:COM+系统应用程序 启动方式:手动 状态:已停止 名称: 加密服务 启动模式:自动 状态:运行 名称:DCOM 服务器进程启动器 启动模式:自动 状态:运行 名称:DHCP客户端 启动模式:自动 状态:运行 名称:逻辑磁盘管理器管理服务 启动方式:手动 状态:已停止 名称:逻辑磁盘管理器 启动模式:自动 状态:运行 名称:DNS客户端 启动模式:自动 状态:运行 名称: 有线自动配置 启动方式:手动 状态:已停止 名称:可扩展身份验证协议服务 启动方式:手动 状态:已停止 名称:错误报告服务 启动模式:禁用 状态:已停止 名称:事件日志 启动模式:自动 状态:运行 名称:COM+事件系统 启动方式:手动 状态:运行 名称:快速用户切换兼容性 启动方式:手动 状态:已停止 名称:FlipShare 服务 启动模式:自动 状态:运行 名称: Windows Presentation Foundation 字体缓存 3.0.0.0 启动方式:手动 状态:已停止 名称: 帮助与支持 启动模式:自动 状态:运行 名称:HID 输入服务 启动模式:自动 状态:运行 名称:健康密钥和证书管理服务 启动方式:手动 状态:已停止 名称:HTTP SSL 启动方式:手动 状态:已停止 名称:InstallDriver 表管理器 启动方式:手动 状态:已停止 名称: Windows CardSpace 启动方式:手动 状态:已停止 名称:IMAPI CD 刻录 COM 服务 启动模式:禁用 状态:已停止 名称: iPod服务 启动方式:手动 状态:已停止 名称:Java 快速入门 启动模式:禁用 状态:已停止 名称:服务器 启动模式:自动 状态:运行 名称: 工作站 启动模式:自动 状态:运行 名称: TCP/IP NetBIOS 帮助程序 启动模式:自动 状态:运行 名称:McAfee 框架服务 启动模式:自动 状态:运行 名称:迈克菲·麦克希尔德 启动模式:自动 状态:运行 名称:迈克菲任务管理器 启动模式:自动 状态:运行 名称: 机器调试管理器 启动模式:自动 状态:运行 名称: 信使 启动模式:禁用 状态:已停止 名称: 视觉控制经理 启动模式:禁用 状态:已停止 名称:NetMeeting远程桌面共享 启动模式:禁用 状态:已停止 名称:分布式事务协调器 启动方式:手动 状态:已停止 名称: Windows 安装程序 启动方式:手动 状态:已停止 名称:网络访问保护代理 启动方式:手动 状态:已停止 名称:网络DDE 启动模式:禁用 状态:已停止 名称:网络DDE DSDM 启动模式:禁用 状态:已停止 名称: 网络登录 启动模式:自动 状态:运行 名称: 网络连接 启动方式:手动 状态:运行 名称:Net.Tcp端口共享服务 启动模式:禁用 状态:已停止 名称:网络位置感知(NLA) 启动方式:手动 状态:运行 姓名: NLCS 代理 启动模式:自动 状态:运行 名称:NT LM 安全支持提供商 启动模式:禁用 状态:已停止 名称: 可移动存储 启动方式:手动 状态:已停止 名称:Microsoft Office 诊断服务 启动模式:禁用 状态:已停止 名称: Office 源引擎 启动方式:手动 状态:已停止 名称: 即插即用 启动模式:自动 状态:运行 名称:Pml驱动HPZ12 启动模式:自动 状态:已停止 名称:IPSEC 服务 启动模式:自动 状态:运行 名称:受保护的存储 启动模式:自动 状态:运行 名称:远程访问自动连接管理器 启动方式:手动 状态:已停止 名称:远程访问连接管理器 启动方式:手动 状态:已停止 名称:远程桌面帮助会话管理器 启动方式:手动 状态:已停止 名称:路由和远程访问 启动模式:禁用 状态:已停止 名称:远程注册表 启动模式:禁用 状态:已停止 名称:远程过程调用 (RPC) 定位器 启动方式:手动 状态:已停止 名称:远程过程调用(RPC) 启动模式:自动 状态:运行 名称:QoS RSVP 启动方式:手动 状态:已停止 姓名: 安全客户经理 启动模式:自动 状态:运行 名称: 智能卡 启动方式:手动 状态:已停止 名称:任务调度器 启动模式:自动 状态:运行 名称:辅助登录 启动模式:自动 状态:运行 名称:系统事件通知 启动模式:自动 状态:运行 名称:Windows 防火墙/Internet 连接共享 (ICS) 启动模式:自动 状态:运行 名称: 外壳硬件检测 启动模式:自动 状态:运行 名称:后台打印程序 启动模式:自动 状态:运行 名称:系统还原服务 启动模式:自动 状态:已停止 名称:SSDP发现服务 启动方式:手动 状态:运行 名称:Windows 图像采集 (WIA) 启动模式:自动 状态:运行 名称:MS Software Shadow Copy Provider 启动方式:手动 状态:已停止 名称:系统接口服务 启动模式:自动 状态:运行 名称:性能日志和警报 启动模式:禁用 状态:已停止 名称: 电话 启动模式:禁用 状态:已停止 名称: 终端服务 启动方式:手动 状态:运行 名称: 主题 启动模式:禁用 状态:已停止 名称: 远程登录 启动模式:禁用 状态:已停止 名称:分布式链接跟踪客户端 启动模式:自动 状态:运行 名称: 通用即插即用设备主机 启动方式:手动 状态:已停止 名称: 不间断电源 启动模式:禁用 状态:已停止 名称:卷影复制 启动方式:手动 状态:已停止 名称: Windows 时间 启动模式:自动 状态:运行 名称: 网络客户端 启动模式:自动 状态:运行 名称:Windows Defender 启动模式:自动 状态:运行 名称:Windows管理工具 启动模式:自动 状态:运行 名称:戴尔无线 WLAN 托盘服务 启动模式:自动 状态:运行 名称:便携式媒体序列号服务 启动模式:禁用 状态:已停止 名称:Windows Management Instrumentation 驱动程序扩展 启动方式:手动 状态:已停止 名称:WMI 性能适配器 启动方式:手动 状态:已停止 名称:Windows Media Player 网络共享服务 启动方式:手动 状态:已停止 名称:安全中心 启动模式:自动 状态:已停止 名称:Windows 搜索 启动模式:自动 状态:运行 名称:自动更新 启动模式:自动 状态:运行 名称:Windows Driver Foundation - 用户模式驱动程序框架 启动方式:手动 状态:已停止 名称:无线零配置 启动模式:自动 状态:已停止 名称:网络配置服务 启动方式:手动 状态:已停止

进程:

名称:系统空闲进程 工作集:28KB 名称: 系统 工作集:244KB 名称: smss.exe 工作集:428KB 名称: csrss.exe 工作集:3984KB 名称: winlogon.exe 工作集:3944KB 名称: 服务.exe 工作集:3612KB 名称: lsass.exe 工作集:5344KB 名称: ati2evxx.exe 工作集:3036KB 名称: svchost.exe 工作集:5076KB 名称: svchost.exe 工作集:5384KB 名称: MsMpEng.exe 工作集:39384KB 名称: svchost.exe 工作集:23792KB 名称: svchost.exe 工作集:4280KB 名称: svchost.exe 工作集:4944KB 名称: WLTRYSVC.EXE 工作集:1652KB 名称: BCMWLTRY.EXE 工作集:9820KB 名称: spoolsv.exe 工作集:8364KB 名称: svchost.exe 工作集:5356KB 名称: AppleMobileDeviceService.exe 工作集:4284KB 名称: mDNSResponder.exe 工作集:4368KB 名称: FlipShareService.exe 工作集:5316KB 名称: FrameworkService.exe 工作集:6048KB 名称: mcshield.exe 工作集:55800KB 名称: vstskmgr.exe 工作集:564KB 名称: mdm.exe 工作集:2748KB 名称: csagtprosvc.exe 工作集:5644KB 名称: naPrdMgr.exe 工作集:2044KB 名称: svchost.exe 工作集:4308KB 名称: 搜索索引器.exe 工作集:20460KB 名称: svchost.exe 工作集:21864KB 名称: unsecapp.exe 工作集:3828KB 名称: alg.exe 工作集:4336KB 名称: wmiprvse.exe 工作集:7576KB 名称: ati2evxx.exe 工作集:3600KB 名称: 资源管理器.exe 工作集:33096KB 名称: SynTPEnh.exe 工作集:4736KB 名称: WLTRAY.EXE 工作集:6644KB 名称: MSASCui.exe 工作集:7824KB 名称: shstat.exe 工作集:820KB 名称: UdaterUI.exe 工作集:2304KB 名称: stsystra.exe 工作集:8100KB 名称: Mctray.exe 工作集:2396KB 名称: ctfmon.exe 工作集:3252KB 名称: DyKnowLogSender.exe 工作集:23972KB

I have a windows service that is running under the credentials of the system account. The service periodically polls windows for the active console session id, i.e. the interactive logged in windows user, and then retrieves the user token associated with the active console session id by pinvoking the wtsapi32.dll function WTSQueryUserToken(…). This implementation works flawlessly 99.9% percent of the time in the field. Lately however, I have found a customer where this implementation periodically (but never consistently) fails to retrieve the user token of the active console session id.

See customer's os info at the bottom of this post.

When WTSQueryUserToken() fails, GetLastError() returns the Windows System error code 1723.

The description of error code 1723: “The RPC server is too busy to complete this operation”

Here is example code snippet demonstrating the implementation:

int ActiveSession = 0;
Win32Wrapper.GetActiveConsoleSessionId(ref ActiveSession);
IntPtr UserToken = IntPtr.Zero;

if(!Win32Wrapper.WTSQueryUserToken(ActiveSession, ref UserToken))
{
   int myErr = Convert.ToInt32(Win32Wrapper.GetLastError());
   log("Failed to retrieve UserToken." + myErr.ToString());
   return;
}
else
{
   log("Retrieved User Token");
}

Does anyone know what might be the culprit ?

Here’s the customer’s setup:

  • Authentication: Active Directory
  • Operating System:
  • Microsoft Windows NT 5.1.2600 Service
  • Pack 3 Current UI Culture: en-US
  • Current Culture: en-US CLR
  • Version: 2.0.50727.3603
  • IE Version: 8.0.6001.18702
  • System type: 32 bit Free
  • Physical Memory: 411MB Total
  • Physical Memory: 893MB System
  • Manufacturer: Dell Inc.
  • Model: Vostro 1000
  • Processor 1: AMD Athlon(tm) 64 X2 Dual-Core Processor TK-57

Services:

Name: Alerter
Start Mode: Disabled
State: Stopped
Name: Application Layer Gateway Service
Start Mode: Manual
State: Running
Name: Apple Mobile Device
Start Mode: Auto
State: Running
Name: Application Management
Start Mode: Manual
State: Stopped
Name: ASP.NET State Service
Start Mode: Manual
State: Stopped
Name: Ati HotKey Poller
Start Mode: Auto
State: Running
Name: Windows Audio
Start Mode: Auto
State: Running
Name: Background Intelligent Transfer Service
Start Mode: Auto
State: Running
Name: Bonjour Service
Start Mode: Auto
State: Running
Name: Computer Browser
Start Mode: Auto
State: Running
Name: Indexing Service
Start Mode: Manual
State: Stopped
Name: ClipBook
Start Mode: Disabled
State: Stopped
Name: .NET Runtime Optimization Service v2.0.50727_X86
Start Mode: Manual
State: Stopped
Name: COM+ System Application
Start Mode: Manual
State: Stopped
Name: Cryptographic Services
Start Mode: Auto
State: Running
Name: DCOM Server Process Launcher
Start Mode: Auto
State: Running
Name: DHCP Client
Start Mode: Auto
State: Running
Name: Logical Disk Manager Administrative Service
Start Mode: Manual
State: Stopped
Name: Logical Disk Manager
Start Mode: Auto
State: Running
Name: DNS Client
Start Mode: Auto
State: Running
Name: Wired AutoConfig
Start Mode: Manual
State: Stopped
Name: Extensible Authentication Protocol Service
Start Mode: Manual
State: Stopped
Name: Error Reporting Service
Start Mode: Disabled
State: Stopped
Name: Event Log
Start Mode: Auto
State: Running
Name: COM+ Event System
Start Mode: Manual
State: Running
Name: Fast User Switching Compatibility
Start Mode: Manual
State: Stopped
Name: FlipShare Service
Start Mode: Auto
State: Running
Name: Windows Presentation Foundation Font Cache 3.0.0.0
Start Mode: Manual
State: Stopped
Name: Help and Support
Start Mode: Auto
State: Running
Name: HID Input Service
Start Mode: Auto
State: Running
Name: Health Key and Certificate Management Service
Start Mode: Manual
State: Stopped
Name: HTTP SSL
Start Mode: Manual
State: Stopped
Name: InstallDriver Table Manager
Start Mode: Manual
State: Stopped
Name: Windows CardSpace
Start Mode: Manual
State: Stopped
Name: IMAPI CD-Burning COM Service
Start Mode: Disabled
State: Stopped
Name: iPod Service
Start Mode: Manual
State: Stopped
Name: Java Quick Starter
Start Mode: Disabled
State: Stopped
Name: Server
Start Mode: Auto
State: Running
Name: Workstation
Start Mode: Auto
State: Running
Name: TCP/IP NetBIOS Helper
Start Mode: Auto
State: Running
Name: McAfee Framework Service
Start Mode: Auto
State: Running
Name: McAfee McShield
Start Mode: Auto
State: Running
Name: McAfee Task Manager
Start Mode: Auto
State: Running
Name: Machine Debug Manager
Start Mode: Auto
State: Running
Name: Messenger
Start Mode: Disabled
State: Stopped
Name: Vision Control Manager
Start Mode: Disabled
State: Stopped
Name: NetMeeting Remote Desktop Sharing
Start Mode: Disabled
State: Stopped
Name: Distributed Transaction Coordinator
Start Mode: Manual
State: Stopped
Name: Windows Installer
Start Mode: Manual
State: Stopped
Name: Network Access Protection Agent
Start Mode: Manual
State: Stopped
Name: Network DDE
Start Mode: Disabled
State: Stopped
Name: Network DDE DSDM
Start Mode: Disabled
State: Stopped
Name: Net Logon
Start Mode: Auto
State: Running
Name: Network Connections
Start Mode: Manual
State: Running
Name: Net.Tcp Port Sharing Service
Start Mode: Disabled
State: Stopped
Name: Network Location Awareness (NLA)
Start Mode: Manual
State: Running
Name: NLCS Agent
Start Mode: Auto
State: Running
Name: NT LM Security Support Provider
Start Mode: Disabled
State: Stopped
Name: Removable Storage
Start Mode: Manual
State: Stopped
Name: Microsoft Office Diagnostics Service
Start Mode: Disabled
State: Stopped
Name: Office Source Engine
Start Mode: Manual
State: Stopped
Name: Plug and Play
Start Mode: Auto
State: Running
Name: Pml Driver HPZ12
Start Mode: Auto
State: Stopped
Name: IPSEC Services
Start Mode: Auto
State: Running
Name: Protected Storage
Start Mode: Auto
State: Running
Name: Remote Access Auto Connection Manager
Start Mode: Manual
State: Stopped
Name: Remote Access Connection Manager
Start Mode: Manual
State: Stopped
Name: Remote Desktop Help Session Manager
Start Mode: Manual
State: Stopped
Name: Routing and Remote Access
Start Mode: Disabled
State: Stopped
Name: Remote Registry
Start Mode: Disabled
State: Stopped
Name: Remote Procedure Call (RPC) Locator
Start Mode: Manual
State: Stopped
Name: Remote Procedure Call (RPC)
Start Mode: Auto
State: Running
Name: QoS RSVP
Start Mode: Manual
State: Stopped
Name: Security Accounts Manager
Start Mode: Auto
State: Running
Name: Smart Card
Start Mode: Manual
State: Stopped
Name: Task Scheduler
Start Mode: Auto
State: Running
Name: Secondary Logon
Start Mode: Auto
State: Running
Name: System Event Notification
Start Mode: Auto
State: Running
Name: Windows Firewall/Internet Connection Sharing (ICS)
Start Mode: Auto
State: Running
Name: Shell Hardware Detection
Start Mode: Auto
State: Running
Name: Print Spooler
Start Mode: Auto
State: Running
Name: System Restore Service
Start Mode: Auto
State: Stopped
Name: SSDP Discovery Service
Start Mode: Manual
State: Running
Name: Windows Image Acquisition (WIA)
Start Mode: Auto
State: Running
Name: MS Software Shadow Copy Provider
Start Mode: Manual
State: Stopped
Name: System Interface Service
Start Mode: Auto
State: Running
Name: Performance Logs and Alerts
Start Mode: Disabled
State: Stopped
Name: Telephony
Start Mode: Disabled
State: Stopped
Name: Terminal Services
Start Mode: Manual
State: Running
Name: Themes
Start Mode: Disabled
State: Stopped
Name: Telnet
Start Mode: Disabled
State: Stopped
Name: Distributed Link Tracking Client
Start Mode: Auto
State: Running
Name: Universal Plug and Play Device Host
Start Mode: Manual
State: Stopped
Name: Uninterruptible Power Supply
Start Mode: Disabled
State: Stopped
Name: Volume Shadow Copy
Start Mode: Manual
State: Stopped
Name: Windows Time
Start Mode: Auto
State: Running
Name: WebClient
Start Mode: Auto
State: Running
Name: Windows Defender
Start Mode: Auto
State: Running
Name: Windows Management Instrumentation
Start Mode: Auto
State: Running
Name: Dell Wireless WLAN Tray Service
Start Mode: Auto
State: Running
Name: Portable Media Serial Number Service
Start Mode: Disabled
State: Stopped
Name: Windows Management Instrumentation Driver Extensions
Start Mode: Manual
State: Stopped
Name: WMI Performance Adapter
Start Mode: Manual
State: Stopped
Name: Windows Media Player Network Sharing Service
Start Mode: Manual
State: Stopped
Name: Security Center
Start Mode: Auto
State: Stopped
Name: Windows Search
Start Mode: Auto
State: Running
Name: Automatic Updates
Start Mode: Auto
State: Running
Name: Windows Driver Foundation - User-mode Driver Framework
Start Mode: Manual
State: Stopped
Name: Wireless Zero Configuration
Start Mode: Auto
State: Stopped
Name: Network Provisioning Service
Start Mode: Manual
State: Stopped

Processes:

Name: System Idle Process
Working Set: 28KB
Name: System
Working Set: 244KB
Name: smss.exe
Working Set: 428KB
Name: csrss.exe
Working Set: 3984KB
Name: winlogon.exe
Working Set: 3944KB
Name: services.exe
Working Set: 3612KB
Name: lsass.exe
Working Set: 5344KB
Name: ati2evxx.exe
Working Set: 3036KB
Name: svchost.exe
Working Set: 5076KB
Name: svchost.exe
Working Set: 5384KB
Name: MsMpEng.exe
Working Set: 39384KB
Name: svchost.exe
Working Set: 23792KB
Name: svchost.exe
Working Set: 4280KB
Name: svchost.exe
Working Set: 4944KB
Name: WLTRYSVC.EXE
Working Set: 1652KB
Name: BCMWLTRY.EXE
Working Set: 9820KB
Name: spoolsv.exe
Working Set: 8364KB
Name: svchost.exe
Working Set: 5356KB
Name: AppleMobileDeviceService.exe
Working Set: 4284KB
Name: mDNSResponder.exe
Working Set: 4368KB
Name: FlipShareService.exe
Working Set: 5316KB
Name: FrameworkService.exe
Working Set: 6048KB
Name: mcshield.exe
Working Set: 55800KB
Name: vstskmgr.exe
Working Set: 564KB
Name: mdm.exe
Working Set: 2748KB
Name: csagtprosvc.exe
Working Set: 5644KB
Name: naPrdMgr.exe
Working Set: 2044KB
Name: svchost.exe
Working Set: 4308KB
Name: searchindexer.exe
Working Set: 20460KB
Name: svchost.exe
Working Set: 21864KB
Name: unsecapp.exe
Working Set: 3828KB
Name: alg.exe
Working Set: 4336KB
Name: wmiprvse.exe
Working Set: 7576KB
Name: ati2evxx.exe
Working Set: 3600KB
Name: explorer.exe
Working Set: 33096KB
Name: SynTPEnh.exe
Working Set: 4736KB
Name: WLTRAY.EXE
Working Set: 6644KB
Name: MSASCui.exe
Working Set: 7824KB
Name: shstat.exe
Working Set: 820KB
Name: UdaterUI.exe
Working Set: 2304KB
Name: stsystra.exe
Working Set: 8100KB
Name: Mctray.exe
Working Set: 2396KB
Name: ctfmon.exe
Working Set: 3252KB
Name: DyKnowLogSender.exe
Working Set: 23972KB

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

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

发布评论

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

评论(2

此岸叶落 2024-08-18 14:09:26

我曾经遇到过这个问题。因此,我建议稍后重复此调用(使用睡眠)。如果成功率达到 99%,那么很可能再尝试几次就会成功。我还会添加一个计数器,这样就不会出现无限循环。

I had this problem once. So I advise to repeat this call some time later (using Sleep). If it works 99% then it is likely that it will work after trying several more times. I also would add a counter so there is no infinite loop.

烟燃烟灭 2024-08-18 14:09:26

Win32Wrapper.GetLastError 实际上是调用 GetLastError 吗?无法从托管代码可靠地调用该函数。相反,您应该将 SetLastError=true 添加到设置错误的所有函数的 DllImport 属性(在您的情况下为 WTSQueryUserToken),然后使用 Marshal.GetLastWin32Error() 检查结果。

Is Win32Wrapper.GetLastError actually calling GetLastError? That function can't be reliably called from managed code. Instead, you should add SetLastError=true to the DllImport attribute of all functions that sets the error (WTSQueryUserToken in your case), and then check the result with Marshal.GetLastWin32Error().

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