ホーム › System.RemoteDesktop › WTSSendMessageW
WTSSendMessageW
関数指定セッションにメッセージボックスを表示して応答を取得する。
シグネチャ
// WTSAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL WTSSendMessageW(
HANDLE hServer, // optional
DWORD SessionId,
LPWSTR pTitle,
DWORD TitleLength,
LPWSTR pMessage,
DWORD MessageLength,
MESSAGEBOX_STYLE Style,
DWORD Timeout,
MESSAGEBOX_RESULT* pResponse,
BOOL bWait
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hServer | HANDLE | optional |
| SessionId | DWORD | in |
| pTitle | LPWSTR | in |
| TitleLength | DWORD | in |
| pMessage | LPWSTR | in |
| MessageLength | DWORD | in |
| Style | MESSAGEBOX_STYLE | in |
| Timeout | DWORD | in |
| pResponse | MESSAGEBOX_RESULT* | out |
| bWait | BOOL | in |
戻り値の型: BOOL
各言語での呼び出し定義
// WTSAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL WTSSendMessageW(
HANDLE hServer, // optional
DWORD SessionId,
LPWSTR pTitle,
DWORD TitleLength,
LPWSTR pMessage,
DWORD MessageLength,
MESSAGEBOX_STYLE Style,
DWORD Timeout,
MESSAGEBOX_RESULT* pResponse,
BOOL bWait
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool WTSSendMessageW(
IntPtr hServer, // HANDLE optional
uint SessionId, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pTitle, // LPWSTR
uint TitleLength, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pMessage, // LPWSTR
uint MessageLength, // DWORD
uint Style, // MESSAGEBOX_STYLE
uint Timeout, // DWORD
out int pResponse, // MESSAGEBOX_RESULT* out
bool bWait // BOOL
);<DllImport("WTSAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSSendMessageW(
hServer As IntPtr, ' HANDLE optional
SessionId As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pTitle As String, ' LPWSTR
TitleLength As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pMessage As String, ' LPWSTR
MessageLength As UInteger, ' DWORD
Style As UInteger, ' MESSAGEBOX_STYLE
Timeout As UInteger, ' DWORD
<Out> ByRef pResponse As Integer, ' MESSAGEBOX_RESULT* out
bWait As Boolean ' BOOL
) As Boolean
End Function' hServer : HANDLE optional
' SessionId : DWORD
' pTitle : LPWSTR
' TitleLength : DWORD
' pMessage : LPWSTR
' MessageLength : DWORD
' Style : MESSAGEBOX_STYLE
' Timeout : DWORD
' pResponse : MESSAGEBOX_RESULT* out
' bWait : BOOL
Declare PtrSafe Function WTSSendMessageW Lib "wtsapi32" ( _
ByVal hServer As LongPtr, _
ByVal SessionId As Long, _
ByVal pTitle As LongPtr, _
ByVal TitleLength As Long, _
ByVal pMessage As LongPtr, _
ByVal MessageLength As Long, _
ByVal Style As Long, _
ByVal Timeout As Long, _
ByRef pResponse As Long, _
ByVal bWait 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
WTSSendMessageW = ctypes.windll.wtsapi32.WTSSendMessageW
WTSSendMessageW.restype = wintypes.BOOL
WTSSendMessageW.argtypes = [
wintypes.HANDLE, # hServer : HANDLE optional
wintypes.DWORD, # SessionId : DWORD
wintypes.LPCWSTR, # pTitle : LPWSTR
wintypes.DWORD, # TitleLength : DWORD
wintypes.LPCWSTR, # pMessage : LPWSTR
wintypes.DWORD, # MessageLength : DWORD
wintypes.DWORD, # Style : MESSAGEBOX_STYLE
wintypes.DWORD, # Timeout : DWORD
ctypes.c_void_p, # pResponse : MESSAGEBOX_RESULT* out
wintypes.BOOL, # bWait : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WTSAPI32.dll')
WTSSendMessageW = Fiddle::Function.new(
lib['WTSSendMessageW'],
[
Fiddle::TYPE_VOIDP, # hServer : HANDLE optional
-Fiddle::TYPE_INT, # SessionId : DWORD
Fiddle::TYPE_VOIDP, # pTitle : LPWSTR
-Fiddle::TYPE_INT, # TitleLength : DWORD
Fiddle::TYPE_VOIDP, # pMessage : LPWSTR
-Fiddle::TYPE_INT, # MessageLength : DWORD
-Fiddle::TYPE_INT, # Style : MESSAGEBOX_STYLE
-Fiddle::TYPE_INT, # Timeout : DWORD
Fiddle::TYPE_VOIDP, # pResponse : MESSAGEBOX_RESULT* out
Fiddle::TYPE_INT, # bWait : BOOL
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "wtsapi32")]
extern "system" {
fn WTSSendMessageW(
hServer: *mut core::ffi::c_void, // HANDLE optional
SessionId: u32, // DWORD
pTitle: *mut u16, // LPWSTR
TitleLength: u32, // DWORD
pMessage: *mut u16, // LPWSTR
MessageLength: u32, // DWORD
Style: u32, // MESSAGEBOX_STYLE
Timeout: u32, // DWORD
pResponse: *mut i32, // MESSAGEBOX_RESULT* out
bWait: i32 // BOOL
) -> 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 WTSSendMessageW(IntPtr hServer, uint SessionId, [MarshalAs(UnmanagedType.LPWStr)] string pTitle, uint TitleLength, [MarshalAs(UnmanagedType.LPWStr)] string pMessage, uint MessageLength, uint Style, uint Timeout, out int pResponse, bool bWait);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSSendMessageW' -Namespace Win32 -PassThru
# $api::WTSSendMessageW(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)#uselib "WTSAPI32.dll"
#func global WTSSendMessageW "WTSSendMessageW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; WTSSendMessageW hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait ; 戻り値は stat
; hServer : HANDLE optional -> "wptr"
; SessionId : DWORD -> "wptr"
; pTitle : LPWSTR -> "wptr"
; TitleLength : DWORD -> "wptr"
; pMessage : LPWSTR -> "wptr"
; MessageLength : DWORD -> "wptr"
; Style : MESSAGEBOX_STYLE -> "wptr"
; Timeout : DWORD -> "wptr"
; pResponse : MESSAGEBOX_RESULT* out -> "wptr"
; bWait : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WTSAPI32.dll"
#cfunc global WTSSendMessageW "WTSSendMessageW" sptr, int, wstr, int, wstr, int, int, int, int, int
; res = WTSSendMessageW(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
; hServer : HANDLE optional -> "sptr"
; SessionId : DWORD -> "int"
; pTitle : LPWSTR -> "wstr"
; TitleLength : DWORD -> "int"
; pMessage : LPWSTR -> "wstr"
; MessageLength : DWORD -> "int"
; Style : MESSAGEBOX_STYLE -> "int"
; Timeout : DWORD -> "int"
; pResponse : MESSAGEBOX_RESULT* out -> "int"
; bWait : BOOL -> "int"; BOOL WTSSendMessageW(HANDLE hServer, DWORD SessionId, LPWSTR pTitle, DWORD TitleLength, LPWSTR pMessage, DWORD MessageLength, MESSAGEBOX_STYLE Style, DWORD Timeout, MESSAGEBOX_RESULT* pResponse, BOOL bWait)
#uselib "WTSAPI32.dll"
#cfunc global WTSSendMessageW "WTSSendMessageW" intptr, int, wstr, int, wstr, int, int, int, int, int
; res = WTSSendMessageW(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
; hServer : HANDLE optional -> "intptr"
; SessionId : DWORD -> "int"
; pTitle : LPWSTR -> "wstr"
; TitleLength : DWORD -> "int"
; pMessage : LPWSTR -> "wstr"
; MessageLength : DWORD -> "int"
; Style : MESSAGEBOX_STYLE -> "int"
; Timeout : DWORD -> "int"
; pResponse : MESSAGEBOX_RESULT* out -> "int"
; bWait : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
procWTSSendMessageW = wtsapi32.NewProc("WTSSendMessageW")
)
// hServer (HANDLE optional), SessionId (DWORD), pTitle (LPWSTR), TitleLength (DWORD), pMessage (LPWSTR), MessageLength (DWORD), Style (MESSAGEBOX_STYLE), Timeout (DWORD), pResponse (MESSAGEBOX_RESULT* out), bWait (BOOL)
r1, _, err := procWTSSendMessageW.Call(
uintptr(hServer),
uintptr(SessionId),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pTitle))),
uintptr(TitleLength),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pMessage))),
uintptr(MessageLength),
uintptr(Style),
uintptr(Timeout),
uintptr(pResponse),
uintptr(bWait),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction WTSSendMessageW(
hServer: THandle; // HANDLE optional
SessionId: DWORD; // DWORD
pTitle: PWideChar; // LPWSTR
TitleLength: DWORD; // DWORD
pMessage: PWideChar; // LPWSTR
MessageLength: DWORD; // DWORD
Style: DWORD; // MESSAGEBOX_STYLE
Timeout: DWORD; // DWORD
pResponse: Pointer; // MESSAGEBOX_RESULT* out
bWait: BOOL // BOOL
): BOOL; stdcall;
external 'WTSAPI32.dll' name 'WTSSendMessageW';result := DllCall("WTSAPI32\WTSSendMessageW"
, "Ptr", hServer ; HANDLE optional
, "UInt", SessionId ; DWORD
, "WStr", pTitle ; LPWSTR
, "UInt", TitleLength ; DWORD
, "WStr", pMessage ; LPWSTR
, "UInt", MessageLength ; DWORD
, "UInt", Style ; MESSAGEBOX_STYLE
, "UInt", Timeout ; DWORD
, "Ptr", pResponse ; MESSAGEBOX_RESULT* out
, "Int", bWait ; BOOL
, "Int") ; return: BOOL●WTSSendMessageW(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait) = DLL("WTSAPI32.dll", "bool WTSSendMessageW(void*, dword, char*, dword, char*, dword, dword, dword, void*, bool)")
# 呼び出し: WTSSendMessageW(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
# hServer : HANDLE optional -> "void*"
# SessionId : DWORD -> "dword"
# pTitle : LPWSTR -> "char*"
# TitleLength : DWORD -> "dword"
# pMessage : LPWSTR -> "char*"
# MessageLength : DWORD -> "dword"
# Style : MESSAGEBOX_STYLE -> "dword"
# Timeout : DWORD -> "dword"
# pResponse : MESSAGEBOX_RESULT* out -> "void*"
# bWait : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。