[英]how to use WtsApi32.dll in lock/Unlock session handler in windows service?
[英]Query with wtsapi32.dll doesn`t work with SAM-Account-Name for japanese users
我正在使用 wtsapi32.dll。 (窗口終端服務api)
我正在嘗試從方法 WTSQueryUserConfig 獲取用戶信息。
[DllImport("wtsapi32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool WTSQueryUserConfig(
[MarshalAs(UnmanagedType.LPStr)] string pServerName,
[MarshalAs(UnmanagedType.LPStr)] string pUserName,
WTS_CONFIG_CLASS wtsConfigClass,
out StringBuilder pBuffer,
out int dataLength);
我的 SAM-Account-Name 用戶有日語(unicode)問題。
我用(unicode版本)修改了我的課程:
[DllImport("wtsapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool WTSQueryUserConfigW(
[MarshalAs(UnmanagedType.LPStr)] string pServerName,
[MarshalAs(UnmanagedType.LPStr)] string pUserName,
WTS_CONFIG_CLASS wtsConfigClass,
out StringBuilder pBuffer,
out int dataLength);
但是我用日語 SAM-Account-Name 調用這個方法它不起作用。
沒有 unicode 字符的用戶可以使用非 unicode 版本方法正常工作。
最后我只使用了輸入參數的字符集配置
[DllImport("wtsapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool WTSQueryUserConfigW(
string pServerName,
string pUserName,
WindowsTerminalServiceConfig wtsConfigClass,
out StringBuilder pBuffer,
out int dataLength);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.