ホーム › System.RemoteDesktop › WTSSetUserConfigW
WTSSetUserConfigW
関数指定ユーザーの構成情報を設定する。
シグネチャ
// WTSAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL WTSSetUserConfigW(
LPWSTR pServerName,
LPWSTR pUserName,
WTS_CONFIG_CLASS WTSConfigClass,
LPWSTR pBuffer,
DWORD DataLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pServerName | LPWSTR | in | 構成情報を設定するサーバー名を指すワイド文字列。NULLまたはローカルでローカルを対象。 |
| pUserName | LPWSTR | in | 対象ユーザーのアカウント名を指すワイド文字列。 |
| WTSConfigClass | WTS_CONFIG_CLASS | in | 設定するユーザー構成情報の種類を示す列挙値。 |
| pBuffer | LPWSTR | in | 設定する構成データを格納したワイド文字バッファ(入力)。 |
| DataLength | DWORD | in | pBufferのデータ長(文字数)。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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 版の利用を推奨。const std = @import("std");
extern "wtsapi32" fn WTSSetUserConfigW(
pServerName: [*c]const u16, // LPWSTR
pUserName: [*c]const u16, // LPWSTR
WTSConfigClass: i32, // WTS_CONFIG_CLASS
pBuffer: [*c]const u16, // LPWSTR
DataLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc WTSSetUserConfigW(
pServerName: WideCString, # LPWSTR
pUserName: WideCString, # LPWSTR
WTSConfigClass: int32, # WTS_CONFIG_CLASS
pBuffer: WideCString, # LPWSTR
DataLength: uint32 # DWORD
): int32 {.importc: "WTSSetUserConfigW", stdcall, dynlib: "WTSAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "wtsapi32");
extern(Windows)
int WTSSetUserConfigW(
const(wchar)* pServerName, // LPWSTR
const(wchar)* pUserName, // LPWSTR
int WTSConfigClass, // WTS_CONFIG_CLASS
const(wchar)* pBuffer, // LPWSTR
uint DataLength // DWORD
);ccall((:WTSSetUserConfigW, "WTSAPI32.dll"), stdcall, Int32,
(Cwstring, Cwstring, Int32, Cwstring, UInt32),
pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
# pServerName : LPWSTR -> Cwstring
# pUserName : LPWSTR -> Cwstring
# WTSConfigClass : WTS_CONFIG_CLASS -> Int32
# pBuffer : LPWSTR -> Cwstring
# DataLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t WTSSetUserConfigW(
const uint16_t* pServerName,
const uint16_t* pUserName,
int32_t WTSConfigClass,
const uint16_t* pBuffer,
uint32_t DataLength);
]]
local wtsapi32 = ffi.load("wtsapi32")
-- wtsapi32.WTSSetUserConfigW(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
-- pServerName : LPWSTR
-- pUserName : LPWSTR
-- WTSConfigClass : WTS_CONFIG_CLASS
-- pBuffer : LPWSTR
-- DataLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('WTSAPI32.dll');
const WTSSetUserConfigW = lib.func('__stdcall', 'WTSSetUserConfigW', 'int32_t', ['str16', 'str16', 'int32_t', 'str16', 'uint32_t']);
// WTSSetUserConfigW(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
// pServerName : LPWSTR -> 'str16'
// pUserName : LPWSTR -> 'str16'
// WTSConfigClass : WTS_CONFIG_CLASS -> 'int32_t'
// pBuffer : LPWSTR -> 'str16'
// DataLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WTSAPI32.dll", {
WTSSetUserConfigW: { parameters: ["buffer", "buffer", "i32", "buffer", "u32"], result: "i32" },
});
// lib.symbols.WTSSetUserConfigW(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
// pServerName : LPWSTR -> "buffer"
// pUserName : LPWSTR -> "buffer"
// WTSConfigClass : WTS_CONFIG_CLASS -> "i32"
// pBuffer : LPWSTR -> "buffer"
// DataLength : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WTSSetUserConfigW(
const uint16_t* pServerName,
const uint16_t* pUserName,
int32_t WTSConfigClass,
const uint16_t* pBuffer,
uint32_t DataLength);
C, "WTSAPI32.dll");
// $ffi->WTSSetUserConfigW(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength);
// pServerName : LPWSTR
// pUserName : LPWSTR
// WTSConfigClass : WTS_CONFIG_CLASS
// pBuffer : LPWSTR
// DataLength : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Wtsapi32 extends StdCallLibrary {
Wtsapi32 INSTANCE = Native.load("wtsapi32", Wtsapi32.class, W32APIOptions.UNICODE_OPTIONS);
boolean WTSSetUserConfigW(
WString pServerName, // LPWSTR
WString pUserName, // LPWSTR
int WTSConfigClass, // WTS_CONFIG_CLASS
WString pBuffer, // LPWSTR
int DataLength // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("wtsapi32")]
lib LibWTSAPI32
fun WTSSetUserConfigW = WTSSetUserConfigW(
pServerName : UInt16*, # LPWSTR
pUserName : UInt16*, # LPWSTR
WTSConfigClass : Int32, # WTS_CONFIG_CLASS
pBuffer : UInt16*, # LPWSTR
DataLength : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WTSSetUserConfigWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32, Pointer<Utf16>, Uint32);
typedef WTSSetUserConfigWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>, int);
final WTSSetUserConfigW = DynamicLibrary.open('WTSAPI32.dll')
.lookupFunction<WTSSetUserConfigWNative, WTSSetUserConfigWDart>('WTSSetUserConfigW');
// pServerName : LPWSTR -> Pointer<Utf16>
// pUserName : LPWSTR -> Pointer<Utf16>
// WTSConfigClass : WTS_CONFIG_CLASS -> Int32
// pBuffer : LPWSTR -> Pointer<Utf16>
// DataLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WTSSetUserConfigW"
c_WTSSetUserConfigW :: CWString -> CWString -> Int32 -> CWString -> Word32 -> IO CInt
-- pServerName : LPWSTR -> CWString
-- pUserName : LPWSTR -> CWString
-- WTSConfigClass : WTS_CONFIG_CLASS -> Int32
-- pBuffer : LPWSTR -> CWString
-- DataLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wtssetuserconfigw =
foreign "WTSSetUserConfigW"
((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* pServerName : LPWSTR -> (ptr uint16_t) *)
(* pUserName : LPWSTR -> (ptr uint16_t) *)
(* WTSConfigClass : WTS_CONFIG_CLASS -> int32_t *)
(* pBuffer : LPWSTR -> (ptr uint16_t) *)
(* DataLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wtsapi32 (t "WTSAPI32.dll"))
(cffi:use-foreign-library wtsapi32)
(cffi:defcfun ("WTSSetUserConfigW" wtsset-user-config-w :convention :stdcall) :int32
(p-server-name (:string :encoding :utf-16le)) ; LPWSTR
(p-user-name (:string :encoding :utf-16le)) ; LPWSTR
(wtsconfig-class :int32) ; WTS_CONFIG_CLASS
(p-buffer (:string :encoding :utf-16le)) ; LPWSTR
(data-length :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WTSSetUserConfigW = Win32::API::More->new('WTSAPI32',
'BOOL WTSSetUserConfigW(LPCWSTR pServerName, LPCWSTR pUserName, int WTSConfigClass, LPCWSTR pBuffer, DWORD DataLength)');
# my $ret = $WTSSetUserConfigW->Call($pServerName, $pUserName, $WTSConfigClass, $pBuffer, $DataLength);
# pServerName : LPWSTR -> LPCWSTR
# pUserName : LPWSTR -> LPCWSTR
# WTSConfigClass : WTS_CONFIG_CLASS -> int
# pBuffer : LPWSTR -> LPCWSTR
# DataLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f WTSSetUserConfigA (ANSI版) — 指定ユーザーの構成情報を設定する。
使用する型