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

WTSSetUserConfigW

関数
指定ユーザーの構成情報を設定する。
DLLWTSAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL WTSSetUserConfigW(
    LPWSTR pServerName,
    LPWSTR pUserName,
    WTS_CONFIG_CLASS WTSConfigClass,
    LPWSTR pBuffer,
    DWORD DataLength
);

パラメーター

名前方向
pServerNameLPWSTRin
pUserNameLPWSTRin
WTSConfigClassWTS_CONFIG_CLASSin
pBufferLPWSTRin
DataLengthDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL WTSSetUserConfigW(
    LPWSTR pServerName,
    LPWSTR pUserName,
    WTS_CONFIG_CLASS WTSConfigClass,
    LPWSTR pBuffer,
    DWORD DataLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool WTSSetUserConfigW(
    [MarshalAs(UnmanagedType.LPWStr)] string pServerName,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pUserName,   // LPWSTR
    int WTSConfigClass,   // WTS_CONFIG_CLASS
    [MarshalAs(UnmanagedType.LPWStr)] string pBuffer,   // LPWSTR
    uint DataLength   // DWORD
);
<DllImport("WTSAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSSetUserConfigW(
    <MarshalAs(UnmanagedType.LPWStr)> pServerName As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pUserName As String,   ' LPWSTR
    WTSConfigClass As Integer,   ' WTS_CONFIG_CLASS
    <MarshalAs(UnmanagedType.LPWStr)> pBuffer As String,   ' LPWSTR
    DataLength As UInteger   ' DWORD
) As Boolean
End Function
' pServerName : LPWSTR
' pUserName : LPWSTR
' WTSConfigClass : WTS_CONFIG_CLASS
' pBuffer : LPWSTR
' DataLength : DWORD
Declare PtrSafe Function WTSSetUserConfigW Lib "wtsapi32" ( _
    ByVal pServerName As LongPtr, _
    ByVal pUserName As LongPtr, _
    ByVal WTSConfigClass As Long, _
    ByVal pBuffer As LongPtr, _
    ByVal DataLength 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

WTSSetUserConfigW = ctypes.windll.wtsapi32.WTSSetUserConfigW
WTSSetUserConfigW.restype = wintypes.BOOL
WTSSetUserConfigW.argtypes = [
    wintypes.LPCWSTR,  # pServerName : LPWSTR
    wintypes.LPCWSTR,  # pUserName : LPWSTR
    ctypes.c_int,  # WTSConfigClass : WTS_CONFIG_CLASS
    wintypes.LPCWSTR,  # pBuffer : LPWSTR
    wintypes.DWORD,  # DataLength : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
	procWTSSetUserConfigW = wtsapi32.NewProc("WTSSetUserConfigW")
)

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