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

WTSSetUserConfigA

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

シグネチャ

// WTSAPI32.dll  (ANSI / -A)
#include <windows.h>

BOOL WTSSetUserConfigA(
    LPSTR pServerName,
    LPSTR pUserName,
    WTS_CONFIG_CLASS WTSConfigClass,
    LPSTR pBuffer,
    DWORD DataLength
);

パラメーター

名前方向
pServerNameLPSTRin
pUserNameLPSTRin
WTSConfigClassWTS_CONFIG_CLASSin
pBufferLPSTRin
DataLengthDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// WTSAPI32.dll  (ANSI / -A)
#include <windows.h>

BOOL WTSSetUserConfigA(
    LPSTR pServerName,
    LPSTR pUserName,
    WTS_CONFIG_CLASS WTSConfigClass,
    LPSTR pBuffer,
    DWORD DataLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool WTSSetUserConfigA(
    [MarshalAs(UnmanagedType.LPStr)] string pServerName,   // LPSTR
    [MarshalAs(UnmanagedType.LPStr)] string pUserName,   // LPSTR
    int WTSConfigClass,   // WTS_CONFIG_CLASS
    [MarshalAs(UnmanagedType.LPStr)] string pBuffer,   // LPSTR
    uint DataLength   // DWORD
);
<DllImport("WTSAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSSetUserConfigA(
    <MarshalAs(UnmanagedType.LPStr)> pServerName As String,   ' LPSTR
    <MarshalAs(UnmanagedType.LPStr)> pUserName As String,   ' LPSTR
    WTSConfigClass As Integer,   ' WTS_CONFIG_CLASS
    <MarshalAs(UnmanagedType.LPStr)> pBuffer As String,   ' LPSTR
    DataLength As UInteger   ' DWORD
) As Boolean
End Function
' pServerName : LPSTR
' pUserName : LPSTR
' WTSConfigClass : WTS_CONFIG_CLASS
' pBuffer : LPSTR
' DataLength : DWORD
Declare PtrSafe Function WTSSetUserConfigA Lib "wtsapi32" ( _
    ByVal pServerName As String, _
    ByVal pUserName As String, _
    ByVal WTSConfigClass As Long, _
    ByVal pBuffer As String, _
    ByVal DataLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WTSSetUserConfigA = ctypes.windll.wtsapi32.WTSSetUserConfigA
WTSSetUserConfigA.restype = wintypes.BOOL
WTSSetUserConfigA.argtypes = [
    wintypes.LPCSTR,  # pServerName : LPSTR
    wintypes.LPCSTR,  # pUserName : LPSTR
    ctypes.c_int,  # WTSConfigClass : WTS_CONFIG_CLASS
    wintypes.LPCSTR,  # pBuffer : LPSTR
    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')
WTSSetUserConfigA = Fiddle::Function.new(
  lib['WTSSetUserConfigA'],
  [
    Fiddle::TYPE_VOIDP,  # pServerName : LPSTR
    Fiddle::TYPE_VOIDP,  # pUserName : LPSTR
    Fiddle::TYPE_INT,  # WTSConfigClass : WTS_CONFIG_CLASS
    Fiddle::TYPE_VOIDP,  # pBuffer : LPSTR
    -Fiddle::TYPE_INT,  # DataLength : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "wtsapi32")]
extern "system" {
    fn WTSSetUserConfigA(
        pServerName: *mut u8,  // LPSTR
        pUserName: *mut u8,  // LPSTR
        WTSConfigClass: i32,  // WTS_CONFIG_CLASS
        pBuffer: *mut u8,  // LPSTR
        DataLength: u32  // DWORD
    ) -> 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 WTSSetUserConfigA([MarshalAs(UnmanagedType.LPStr)] string pServerName, [MarshalAs(UnmanagedType.LPStr)] string pUserName, int WTSConfigClass, [MarshalAs(UnmanagedType.LPStr)] string pBuffer, uint DataLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSSetUserConfigA' -Namespace Win32 -PassThru
# $api::WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
#uselib "WTSAPI32.dll"
#func global WTSSetUserConfigA "WTSSetUserConfigA" sptr, sptr, sptr, sptr, sptr
; WTSSetUserConfigA pServerName, pUserName, WTSConfigClass, pBuffer, DataLength   ; 戻り値は stat
; pServerName : LPSTR -> "sptr"
; pUserName : LPSTR -> "sptr"
; WTSConfigClass : WTS_CONFIG_CLASS -> "sptr"
; pBuffer : LPSTR -> "sptr"
; DataLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WTSAPI32.dll"
#cfunc global WTSSetUserConfigA "WTSSetUserConfigA" str, str, int, str, int
; res = WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
; pServerName : LPSTR -> "str"
; pUserName : LPSTR -> "str"
; WTSConfigClass : WTS_CONFIG_CLASS -> "int"
; pBuffer : LPSTR -> "str"
; DataLength : DWORD -> "int"
; BOOL WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer, DWORD DataLength)
#uselib "WTSAPI32.dll"
#cfunc global WTSSetUserConfigA "WTSSetUserConfigA" str, str, int, str, int
; res = WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
; pServerName : LPSTR -> "str"
; pUserName : LPSTR -> "str"
; WTSConfigClass : WTS_CONFIG_CLASS -> "int"
; pBuffer : LPSTR -> "str"
; DataLength : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
	procWTSSetUserConfigA = wtsapi32.NewProc("WTSSetUserConfigA")
)

// pServerName (LPSTR), pUserName (LPSTR), WTSConfigClass (WTS_CONFIG_CLASS), pBuffer (LPSTR), DataLength (DWORD)
r1, _, err := procWTSSetUserConfigA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pServerName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pUserName))),
	uintptr(WTSConfigClass),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pBuffer))),
	uintptr(DataLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function WTSSetUserConfigA(
  pServerName: PAnsiChar;   // LPSTR
  pUserName: PAnsiChar;   // LPSTR
  WTSConfigClass: Integer;   // WTS_CONFIG_CLASS
  pBuffer: PAnsiChar;   // LPSTR
  DataLength: DWORD   // DWORD
): BOOL; stdcall;
  external 'WTSAPI32.dll' name 'WTSSetUserConfigA';
result := DllCall("WTSAPI32\WTSSetUserConfigA"
    , "AStr", pServerName   ; LPSTR
    , "AStr", pUserName   ; LPSTR
    , "Int", WTSConfigClass   ; WTS_CONFIG_CLASS
    , "AStr", pBuffer   ; LPSTR
    , "UInt", DataLength   ; DWORD
    , "Int")   ; return: BOOL
●WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength) = DLL("WTSAPI32.dll", "bool WTSSetUserConfigA(char*, char*, int, char*, dword)")
# 呼び出し: WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
# pServerName : LPSTR -> "char*"
# pUserName : LPSTR -> "char*"
# WTSConfigClass : WTS_CONFIG_CLASS -> "int"
# pBuffer : LPSTR -> "char*"
# DataLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。