Win32 API 日本語リファレンス
ホームSystem.RemoteDesktop › WTSStartRemoteControlSessionW

WTSStartRemoteControlSessionW

関数
指定セッションのリモート制御セッションを開始する。
DLLWTSAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// WTSAPI32.dll  (Unicode / -W)
#include <windows.h>

BOOL WTSStartRemoteControlSessionW(
    LPWSTR pTargetServerName,
    DWORD TargetLogonId,
    BYTE HotkeyVk,
    WORD HotkeyModifiers
);

パラメーター

名前方向
pTargetServerNameLPWSTRin
TargetLogonIdDWORDin
HotkeyVkBYTEin
HotkeyModifiersWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// WTSAPI32.dll  (Unicode / -W)
#include <windows.h>

BOOL WTSStartRemoteControlSessionW(
    LPWSTR pTargetServerName,
    DWORD TargetLogonId,
    BYTE HotkeyVk,
    WORD HotkeyModifiers
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool WTSStartRemoteControlSessionW(
    [MarshalAs(UnmanagedType.LPWStr)] string pTargetServerName,   // LPWSTR
    uint TargetLogonId,   // DWORD
    byte HotkeyVk,   // BYTE
    ushort HotkeyModifiers   // WORD
);
<DllImport("WTSAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSStartRemoteControlSessionW(
    <MarshalAs(UnmanagedType.LPWStr)> pTargetServerName As String,   ' LPWSTR
    TargetLogonId As UInteger,   ' DWORD
    HotkeyVk As Byte,   ' BYTE
    HotkeyModifiers As UShort   ' WORD
) As Boolean
End Function
' pTargetServerName : LPWSTR
' TargetLogonId : DWORD
' HotkeyVk : BYTE
' HotkeyModifiers : WORD
Declare PtrSafe Function WTSStartRemoteControlSessionW Lib "wtsapi32" ( _
    ByVal pTargetServerName As LongPtr, _
    ByVal TargetLogonId As Long, _
    ByVal HotkeyVk As Byte, _
    ByVal HotkeyModifiers As Integer) 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

WTSStartRemoteControlSessionW = ctypes.windll.wtsapi32.WTSStartRemoteControlSessionW
WTSStartRemoteControlSessionW.restype = wintypes.BOOL
WTSStartRemoteControlSessionW.argtypes = [
    wintypes.LPCWSTR,  # pTargetServerName : LPWSTR
    wintypes.DWORD,  # TargetLogonId : DWORD
    ctypes.c_ubyte,  # HotkeyVk : BYTE
    ctypes.c_ushort,  # HotkeyModifiers : WORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WTSAPI32.dll')
WTSStartRemoteControlSessionW = Fiddle::Function.new(
  lib['WTSStartRemoteControlSessionW'],
  [
    Fiddle::TYPE_VOIDP,  # pTargetServerName : LPWSTR
    -Fiddle::TYPE_INT,  # TargetLogonId : DWORD
    -Fiddle::TYPE_CHAR,  # HotkeyVk : BYTE
    -Fiddle::TYPE_SHORT,  # HotkeyModifiers : WORD
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wtsapi32")]
extern "system" {
    fn WTSStartRemoteControlSessionW(
        pTargetServerName: *mut u16,  // LPWSTR
        TargetLogonId: u32,  // DWORD
        HotkeyVk: u8,  // BYTE
        HotkeyModifiers: u16  // WORD
    ) -> 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 WTSStartRemoteControlSessionW([MarshalAs(UnmanagedType.LPWStr)] string pTargetServerName, uint TargetLogonId, byte HotkeyVk, ushort HotkeyModifiers);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSStartRemoteControlSessionW' -Namespace Win32 -PassThru
# $api::WTSStartRemoteControlSessionW(pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers)
#uselib "WTSAPI32.dll"
#func global WTSStartRemoteControlSessionW "WTSStartRemoteControlSessionW" wptr, wptr, wptr, wptr
; WTSStartRemoteControlSessionW pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers   ; 戻り値は stat
; pTargetServerName : LPWSTR -> "wptr"
; TargetLogonId : DWORD -> "wptr"
; HotkeyVk : BYTE -> "wptr"
; HotkeyModifiers : WORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WTSAPI32.dll"
#cfunc global WTSStartRemoteControlSessionW "WTSStartRemoteControlSessionW" wstr, int, int, int
; res = WTSStartRemoteControlSessionW(pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers)
; pTargetServerName : LPWSTR -> "wstr"
; TargetLogonId : DWORD -> "int"
; HotkeyVk : BYTE -> "int"
; HotkeyModifiers : WORD -> "int"
; BOOL WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, DWORD TargetLogonId, BYTE HotkeyVk, WORD HotkeyModifiers)
#uselib "WTSAPI32.dll"
#cfunc global WTSStartRemoteControlSessionW "WTSStartRemoteControlSessionW" wstr, int, int, int
; res = WTSStartRemoteControlSessionW(pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers)
; pTargetServerName : LPWSTR -> "wstr"
; TargetLogonId : DWORD -> "int"
; HotkeyVk : BYTE -> "int"
; HotkeyModifiers : WORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
	procWTSStartRemoteControlSessionW = wtsapi32.NewProc("WTSStartRemoteControlSessionW")
)

// pTargetServerName (LPWSTR), TargetLogonId (DWORD), HotkeyVk (BYTE), HotkeyModifiers (WORD)
r1, _, err := procWTSStartRemoteControlSessionW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pTargetServerName))),
	uintptr(TargetLogonId),
	uintptr(HotkeyVk),
	uintptr(HotkeyModifiers),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function WTSStartRemoteControlSessionW(
  pTargetServerName: PWideChar;   // LPWSTR
  TargetLogonId: DWORD;   // DWORD
  HotkeyVk: Byte;   // BYTE
  HotkeyModifiers: Word   // WORD
): BOOL; stdcall;
  external 'WTSAPI32.dll' name 'WTSStartRemoteControlSessionW';
result := DllCall("WTSAPI32\WTSStartRemoteControlSessionW"
    , "WStr", pTargetServerName   ; LPWSTR
    , "UInt", TargetLogonId   ; DWORD
    , "UChar", HotkeyVk   ; BYTE
    , "UShort", HotkeyModifiers   ; WORD
    , "Int")   ; return: BOOL
●WTSStartRemoteControlSessionW(pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers) = DLL("WTSAPI32.dll", "bool WTSStartRemoteControlSessionW(char*, dword, byte, int)")
# 呼び出し: WTSStartRemoteControlSessionW(pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers)
# pTargetServerName : LPWSTR -> "char*"
# TargetLogonId : DWORD -> "dword"
# HotkeyVk : BYTE -> "byte"
# HotkeyModifiers : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。