ホーム › System.RemoteDesktop › WTSSendMessageA
WTSSendMessageA
関数指定セッションにメッセージボックスを表示して応答を取得する。
シグネチャ
// WTSAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL WTSSendMessageA(
HANDLE hServer, // optional
DWORD SessionId,
LPSTR pTitle,
DWORD TitleLength,
LPSTR pMessage,
DWORD MessageLength,
MESSAGEBOX_STYLE Style,
DWORD Timeout,
MESSAGEBOX_RESULT* pResponse,
BOOL bWait
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hServer | HANDLE | optional |
| SessionId | DWORD | in |
| pTitle | LPSTR | in |
| TitleLength | DWORD | in |
| pMessage | LPSTR | in |
| MessageLength | DWORD | in |
| Style | MESSAGEBOX_STYLE | in |
| Timeout | DWORD | in |
| pResponse | MESSAGEBOX_RESULT* | out |
| bWait | BOOL | in |
戻り値の型: BOOL
各言語での呼び出し定義
// WTSAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL WTSSendMessageA(
HANDLE hServer, // optional
DWORD SessionId,
LPSTR pTitle,
DWORD TitleLength,
LPSTR pMessage,
DWORD MessageLength,
MESSAGEBOX_STYLE Style,
DWORD Timeout,
MESSAGEBOX_RESULT* pResponse,
BOOL bWait
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool WTSSendMessageA(
IntPtr hServer, // HANDLE optional
uint SessionId, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string pTitle, // LPSTR
uint TitleLength, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string pMessage, // LPSTR
uint MessageLength, // DWORD
uint Style, // MESSAGEBOX_STYLE
uint Timeout, // DWORD
out int pResponse, // MESSAGEBOX_RESULT* out
bool bWait // BOOL
);<DllImport("WTSAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSSendMessageA(
hServer As IntPtr, ' HANDLE optional
SessionId As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> pTitle As String, ' LPSTR
TitleLength As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> pMessage As String, ' LPSTR
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 : LPSTR
' TitleLength : DWORD
' pMessage : LPSTR
' MessageLength : DWORD
' Style : MESSAGEBOX_STYLE
' Timeout : DWORD
' pResponse : MESSAGEBOX_RESULT* out
' bWait : BOOL
Declare PtrSafe Function WTSSendMessageA Lib "wtsapi32" ( _
ByVal hServer As LongPtr, _
ByVal SessionId As Long, _
ByVal pTitle As String, _
ByVal TitleLength As Long, _
ByVal pMessage As String, _
ByVal MessageLength As Long, _
ByVal Style As Long, _
ByVal Timeout As Long, _
ByRef pResponse As Long, _
ByVal bWait As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WTSSendMessageA = ctypes.windll.wtsapi32.WTSSendMessageA
WTSSendMessageA.restype = wintypes.BOOL
WTSSendMessageA.argtypes = [
wintypes.HANDLE, # hServer : HANDLE optional
wintypes.DWORD, # SessionId : DWORD
wintypes.LPCSTR, # pTitle : LPSTR
wintypes.DWORD, # TitleLength : DWORD
wintypes.LPCSTR, # pMessage : LPSTR
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')
WTSSendMessageA = Fiddle::Function.new(
lib['WTSSendMessageA'],
[
Fiddle::TYPE_VOIDP, # hServer : HANDLE optional
-Fiddle::TYPE_INT, # SessionId : DWORD
Fiddle::TYPE_VOIDP, # pTitle : LPSTR
-Fiddle::TYPE_INT, # TitleLength : DWORD
Fiddle::TYPE_VOIDP, # pMessage : LPSTR
-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)#[link(name = "wtsapi32")]
extern "system" {
fn WTSSendMessageA(
hServer: *mut core::ffi::c_void, // HANDLE optional
SessionId: u32, // DWORD
pTitle: *mut u8, // LPSTR
TitleLength: u32, // DWORD
pMessage: *mut u8, // LPSTR
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.Ansi, SetLastError = true)]
public static extern bool WTSSendMessageA(IntPtr hServer, uint SessionId, [MarshalAs(UnmanagedType.LPStr)] string pTitle, uint TitleLength, [MarshalAs(UnmanagedType.LPStr)] string pMessage, uint MessageLength, uint Style, uint Timeout, out int pResponse, bool bWait);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSSendMessageA' -Namespace Win32 -PassThru
# $api::WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)#uselib "WTSAPI32.dll"
#func global WTSSendMessageA "WTSSendMessageA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WTSSendMessageA hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait ; 戻り値は stat
; hServer : HANDLE optional -> "sptr"
; SessionId : DWORD -> "sptr"
; pTitle : LPSTR -> "sptr"
; TitleLength : DWORD -> "sptr"
; pMessage : LPSTR -> "sptr"
; MessageLength : DWORD -> "sptr"
; Style : MESSAGEBOX_STYLE -> "sptr"
; Timeout : DWORD -> "sptr"
; pResponse : MESSAGEBOX_RESULT* out -> "sptr"
; bWait : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WTSAPI32.dll"
#cfunc global WTSSendMessageA "WTSSendMessageA" sptr, int, str, int, str, int, int, int, int, int
; res = WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
; hServer : HANDLE optional -> "sptr"
; SessionId : DWORD -> "int"
; pTitle : LPSTR -> "str"
; TitleLength : DWORD -> "int"
; pMessage : LPSTR -> "str"
; MessageLength : DWORD -> "int"
; Style : MESSAGEBOX_STYLE -> "int"
; Timeout : DWORD -> "int"
; pResponse : MESSAGEBOX_RESULT* out -> "int"
; bWait : BOOL -> "int"; BOOL WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle, DWORD TitleLength, LPSTR pMessage, DWORD MessageLength, MESSAGEBOX_STYLE Style, DWORD Timeout, MESSAGEBOX_RESULT* pResponse, BOOL bWait)
#uselib "WTSAPI32.dll"
#cfunc global WTSSendMessageA "WTSSendMessageA" intptr, int, str, int, str, int, int, int, int, int
; res = WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
; hServer : HANDLE optional -> "intptr"
; SessionId : DWORD -> "int"
; pTitle : LPSTR -> "str"
; TitleLength : DWORD -> "int"
; pMessage : LPSTR -> "str"
; 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")
procWTSSendMessageA = wtsapi32.NewProc("WTSSendMessageA")
)
// hServer (HANDLE optional), SessionId (DWORD), pTitle (LPSTR), TitleLength (DWORD), pMessage (LPSTR), MessageLength (DWORD), Style (MESSAGEBOX_STYLE), Timeout (DWORD), pResponse (MESSAGEBOX_RESULT* out), bWait (BOOL)
r1, _, err := procWTSSendMessageA.Call(
uintptr(hServer),
uintptr(SessionId),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pTitle))),
uintptr(TitleLength),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pMessage))),
uintptr(MessageLength),
uintptr(Style),
uintptr(Timeout),
uintptr(pResponse),
uintptr(bWait),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction WTSSendMessageA(
hServer: THandle; // HANDLE optional
SessionId: DWORD; // DWORD
pTitle: PAnsiChar; // LPSTR
TitleLength: DWORD; // DWORD
pMessage: PAnsiChar; // LPSTR
MessageLength: DWORD; // DWORD
Style: DWORD; // MESSAGEBOX_STYLE
Timeout: DWORD; // DWORD
pResponse: Pointer; // MESSAGEBOX_RESULT* out
bWait: BOOL // BOOL
): BOOL; stdcall;
external 'WTSAPI32.dll' name 'WTSSendMessageA';result := DllCall("WTSAPI32\WTSSendMessageA"
, "Ptr", hServer ; HANDLE optional
, "UInt", SessionId ; DWORD
, "AStr", pTitle ; LPSTR
, "UInt", TitleLength ; DWORD
, "AStr", pMessage ; LPSTR
, "UInt", MessageLength ; DWORD
, "UInt", Style ; MESSAGEBOX_STYLE
, "UInt", Timeout ; DWORD
, "Ptr", pResponse ; MESSAGEBOX_RESULT* out
, "Int", bWait ; BOOL
, "Int") ; return: BOOL●WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait) = DLL("WTSAPI32.dll", "bool WTSSendMessageA(void*, dword, char*, dword, char*, dword, dword, dword, void*, bool)")
# 呼び出し: WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
# hServer : HANDLE optional -> "void*"
# SessionId : DWORD -> "dword"
# pTitle : LPSTR -> "char*"
# TitleLength : DWORD -> "dword"
# pMessage : LPSTR -> "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)。