ホーム › System.RemoteDesktop › WTSQuerySessionInformationW
WTSQuerySessionInformationW
関数指定セッションの情報を情報クラス別に取得する。
シグネチャ
// WTSAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL WTSQuerySessionInformationW(
HANDLE hServer, // optional
DWORD SessionId,
WTS_INFO_CLASS WTSInfoClass,
LPWSTR* ppBuffer,
DWORD* pBytesReturned
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hServer | HANDLE | optional |
| SessionId | DWORD | in |
| WTSInfoClass | WTS_INFO_CLASS | in |
| ppBuffer | LPWSTR* | out |
| pBytesReturned | DWORD* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// WTSAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL WTSQuerySessionInformationW(
HANDLE hServer, // optional
DWORD SessionId,
WTS_INFO_CLASS WTSInfoClass,
LPWSTR* ppBuffer,
DWORD* pBytesReturned
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool WTSQuerySessionInformationW(
IntPtr hServer, // HANDLE optional
uint SessionId, // DWORD
int WTSInfoClass, // WTS_INFO_CLASS
IntPtr ppBuffer, // LPWSTR* out
out uint pBytesReturned // DWORD* out
);<DllImport("WTSAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSQuerySessionInformationW(
hServer As IntPtr, ' HANDLE optional
SessionId As UInteger, ' DWORD
WTSInfoClass As Integer, ' WTS_INFO_CLASS
ppBuffer As IntPtr, ' LPWSTR* out
<Out> ByRef pBytesReturned As UInteger ' DWORD* out
) As Boolean
End Function' hServer : HANDLE optional
' SessionId : DWORD
' WTSInfoClass : WTS_INFO_CLASS
' ppBuffer : LPWSTR* out
' pBytesReturned : DWORD* out
Declare PtrSafe Function WTSQuerySessionInformationW Lib "wtsapi32" ( _
ByVal hServer As LongPtr, _
ByVal SessionId As Long, _
ByVal WTSInfoClass As Long, _
ByVal ppBuffer As LongPtr, _
ByRef pBytesReturned As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WTSQuerySessionInformationW = ctypes.windll.wtsapi32.WTSQuerySessionInformationW
WTSQuerySessionInformationW.restype = wintypes.BOOL
WTSQuerySessionInformationW.argtypes = [
wintypes.HANDLE, # hServer : HANDLE optional
wintypes.DWORD, # SessionId : DWORD
ctypes.c_int, # WTSInfoClass : WTS_INFO_CLASS
ctypes.c_void_p, # ppBuffer : LPWSTR* out
ctypes.POINTER(wintypes.DWORD), # pBytesReturned : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WTSAPI32.dll')
WTSQuerySessionInformationW = Fiddle::Function.new(
lib['WTSQuerySessionInformationW'],
[
Fiddle::TYPE_VOIDP, # hServer : HANDLE optional
-Fiddle::TYPE_INT, # SessionId : DWORD
Fiddle::TYPE_INT, # WTSInfoClass : WTS_INFO_CLASS
Fiddle::TYPE_VOIDP, # ppBuffer : LPWSTR* out
Fiddle::TYPE_VOIDP, # pBytesReturned : DWORD* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "wtsapi32")]
extern "system" {
fn WTSQuerySessionInformationW(
hServer: *mut core::ffi::c_void, // HANDLE optional
SessionId: u32, // DWORD
WTSInfoClass: i32, // WTS_INFO_CLASS
ppBuffer: *mut *mut u16, // LPWSTR* out
pBytesReturned: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool WTSQuerySessionInformationW(IntPtr hServer, uint SessionId, int WTSInfoClass, IntPtr ppBuffer, out uint pBytesReturned);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSQuerySessionInformationW' -Namespace Win32 -PassThru
# $api::WTSQuerySessionInformationW(hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned)#uselib "WTSAPI32.dll"
#func global WTSQuerySessionInformationW "WTSQuerySessionInformationW" wptr, wptr, wptr, wptr, wptr
; WTSQuerySessionInformationW hServer, SessionId, WTSInfoClass, varptr(ppBuffer), varptr(pBytesReturned) ; 戻り値は stat
; hServer : HANDLE optional -> "wptr"
; SessionId : DWORD -> "wptr"
; WTSInfoClass : WTS_INFO_CLASS -> "wptr"
; ppBuffer : LPWSTR* out -> "wptr"
; pBytesReturned : DWORD* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WTSAPI32.dll" #cfunc global WTSQuerySessionInformationW "WTSQuerySessionInformationW" sptr, int, int, var, var ; res = WTSQuerySessionInformationW(hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned) ; hServer : HANDLE optional -> "sptr" ; SessionId : DWORD -> "int" ; WTSInfoClass : WTS_INFO_CLASS -> "int" ; ppBuffer : LPWSTR* out -> "var" ; pBytesReturned : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WTSAPI32.dll" #cfunc global WTSQuerySessionInformationW "WTSQuerySessionInformationW" sptr, int, int, sptr, sptr ; res = WTSQuerySessionInformationW(hServer, SessionId, WTSInfoClass, varptr(ppBuffer), varptr(pBytesReturned)) ; hServer : HANDLE optional -> "sptr" ; SessionId : DWORD -> "int" ; WTSInfoClass : WTS_INFO_CLASS -> "int" ; ppBuffer : LPWSTR* out -> "sptr" ; pBytesReturned : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned) #uselib "WTSAPI32.dll" #cfunc global WTSQuerySessionInformationW "WTSQuerySessionInformationW" intptr, int, int, var, var ; res = WTSQuerySessionInformationW(hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned) ; hServer : HANDLE optional -> "intptr" ; SessionId : DWORD -> "int" ; WTSInfoClass : WTS_INFO_CLASS -> "int" ; ppBuffer : LPWSTR* out -> "var" ; pBytesReturned : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned) #uselib "WTSAPI32.dll" #cfunc global WTSQuerySessionInformationW "WTSQuerySessionInformationW" intptr, int, int, intptr, intptr ; res = WTSQuerySessionInformationW(hServer, SessionId, WTSInfoClass, varptr(ppBuffer), varptr(pBytesReturned)) ; hServer : HANDLE optional -> "intptr" ; SessionId : DWORD -> "int" ; WTSInfoClass : WTS_INFO_CLASS -> "int" ; ppBuffer : LPWSTR* out -> "intptr" ; pBytesReturned : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
procWTSQuerySessionInformationW = wtsapi32.NewProc("WTSQuerySessionInformationW")
)
// hServer (HANDLE optional), SessionId (DWORD), WTSInfoClass (WTS_INFO_CLASS), ppBuffer (LPWSTR* out), pBytesReturned (DWORD* out)
r1, _, err := procWTSQuerySessionInformationW.Call(
uintptr(hServer),
uintptr(SessionId),
uintptr(WTSInfoClass),
uintptr(ppBuffer),
uintptr(pBytesReturned),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction WTSQuerySessionInformationW(
hServer: THandle; // HANDLE optional
SessionId: DWORD; // DWORD
WTSInfoClass: Integer; // WTS_INFO_CLASS
ppBuffer: PPWideChar; // LPWSTR* out
pBytesReturned: Pointer // DWORD* out
): BOOL; stdcall;
external 'WTSAPI32.dll' name 'WTSQuerySessionInformationW';result := DllCall("WTSAPI32\WTSQuerySessionInformationW"
, "Ptr", hServer ; HANDLE optional
, "UInt", SessionId ; DWORD
, "Int", WTSInfoClass ; WTS_INFO_CLASS
, "Ptr", ppBuffer ; LPWSTR* out
, "Ptr", pBytesReturned ; DWORD* out
, "Int") ; return: BOOL●WTSQuerySessionInformationW(hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned) = DLL("WTSAPI32.dll", "bool WTSQuerySessionInformationW(void*, dword, int, void*, void*)")
# 呼び出し: WTSQuerySessionInformationW(hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned)
# hServer : HANDLE optional -> "void*"
# SessionId : DWORD -> "dword"
# WTSInfoClass : WTS_INFO_CLASS -> "int"
# ppBuffer : LPWSTR* out -> "void*"
# pBytesReturned : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。