ホーム › System.RemoteDesktop › WTSSetUserConfigA
WTSSetUserConfigA
関数指定ユーザーの構成情報を設定する。
シグネチャ
// WTSAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL WTSSetUserConfigA(
LPSTR pServerName,
LPSTR pUserName,
WTS_CONFIG_CLASS WTSConfigClass,
LPSTR pBuffer,
DWORD DataLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pServerName | LPSTR | in | 構成情報を設定するサーバー名を指すANSI文字列。NULLまたはローカルでローカルを対象。 |
| pUserName | LPSTR | in | 対象ユーザーのアカウント名を指すANSI文字列。 |
| WTSConfigClass | WTS_CONFIG_CLASS | in | 設定するユーザー構成情報の種類を示す列挙値。 |
| pBuffer | LPSTR | in | 設定する構成データを格納したANSIバッファ(入力)。 |
| DataLength | DWORD | in | pBufferのデータ長(文字数)。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "wtsapi32" fn WTSSetUserConfigA(
pServerName: [*c]const u8, // LPSTR
pUserName: [*c]const u8, // LPSTR
WTSConfigClass: i32, // WTS_CONFIG_CLASS
pBuffer: [*c]const u8, // LPSTR
DataLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc WTSSetUserConfigA(
pServerName: cstring, # LPSTR
pUserName: cstring, # LPSTR
WTSConfigClass: int32, # WTS_CONFIG_CLASS
pBuffer: cstring, # LPSTR
DataLength: uint32 # DWORD
): int32 {.importc: "WTSSetUserConfigA", stdcall, dynlib: "WTSAPI32.dll".}pragma(lib, "wtsapi32");
extern(Windows)
int WTSSetUserConfigA(
const(char)* pServerName, // LPSTR
const(char)* pUserName, // LPSTR
int WTSConfigClass, // WTS_CONFIG_CLASS
const(char)* pBuffer, // LPSTR
uint DataLength // DWORD
);ccall((:WTSSetUserConfigA, "WTSAPI32.dll"), stdcall, Int32,
(Cstring, Cstring, Int32, Cstring, UInt32),
pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
# pServerName : LPSTR -> Cstring
# pUserName : LPSTR -> Cstring
# WTSConfigClass : WTS_CONFIG_CLASS -> Int32
# pBuffer : LPSTR -> Cstring
# DataLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WTSSetUserConfigA(
const char* pServerName,
const char* pUserName,
int32_t WTSConfigClass,
const char* pBuffer,
uint32_t DataLength);
]]
local wtsapi32 = ffi.load("wtsapi32")
-- wtsapi32.WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
-- pServerName : LPSTR
-- pUserName : LPSTR
-- WTSConfigClass : WTS_CONFIG_CLASS
-- pBuffer : LPSTR
-- DataLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WTSAPI32.dll');
const WTSSetUserConfigA = lib.func('__stdcall', 'WTSSetUserConfigA', 'int32_t', ['str', 'str', 'int32_t', 'str', 'uint32_t']);
// WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
// pServerName : LPSTR -> 'str'
// pUserName : LPSTR -> 'str'
// WTSConfigClass : WTS_CONFIG_CLASS -> 'int32_t'
// pBuffer : LPSTR -> 'str'
// DataLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WTSAPI32.dll", {
WTSSetUserConfigA: { parameters: ["buffer", "buffer", "i32", "buffer", "u32"], result: "i32" },
});
// lib.symbols.WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength)
// pServerName : LPSTR -> "buffer"
// pUserName : LPSTR -> "buffer"
// WTSConfigClass : WTS_CONFIG_CLASS -> "i32"
// pBuffer : LPSTR -> "buffer"
// DataLength : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WTSSetUserConfigA(
const char* pServerName,
const char* pUserName,
int32_t WTSConfigClass,
const char* pBuffer,
uint32_t DataLength);
C, "WTSAPI32.dll");
// $ffi->WTSSetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength);
// pServerName : LPSTR
// pUserName : LPSTR
// WTSConfigClass : WTS_CONFIG_CLASS
// pBuffer : LPSTR
// 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.ASCII_OPTIONS);
boolean WTSSetUserConfigA(
String pServerName, // LPSTR
String pUserName, // LPSTR
int WTSConfigClass, // WTS_CONFIG_CLASS
String pBuffer, // LPSTR
int DataLength // DWORD
);
}@[Link("wtsapi32")]
lib LibWTSAPI32
fun WTSSetUserConfigA = WTSSetUserConfigA(
pServerName : UInt8*, # LPSTR
pUserName : UInt8*, # LPSTR
WTSConfigClass : Int32, # WTS_CONFIG_CLASS
pBuffer : UInt8*, # LPSTR
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 WTSSetUserConfigANative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Int32, Pointer<Utf8>, Uint32);
typedef WTSSetUserConfigADart = int Function(Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Utf8>, int);
final WTSSetUserConfigA = DynamicLibrary.open('WTSAPI32.dll')
.lookupFunction<WTSSetUserConfigANative, WTSSetUserConfigADart>('WTSSetUserConfigA');
// pServerName : LPSTR -> Pointer<Utf8>
// pUserName : LPSTR -> Pointer<Utf8>
// WTSConfigClass : WTS_CONFIG_CLASS -> Int32
// pBuffer : LPSTR -> Pointer<Utf8>
// DataLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WTSSetUserConfigA"
c_WTSSetUserConfigA :: CString -> CString -> Int32 -> CString -> Word32 -> IO CInt
-- pServerName : LPSTR -> CString
-- pUserName : LPSTR -> CString
-- WTSConfigClass : WTS_CONFIG_CLASS -> Int32
-- pBuffer : LPSTR -> CString
-- DataLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wtssetuserconfiga =
foreign "WTSSetUserConfigA"
(string @-> string @-> int32_t @-> string @-> uint32_t @-> returning int32_t)
(* pServerName : LPSTR -> string *)
(* pUserName : LPSTR -> string *)
(* WTSConfigClass : WTS_CONFIG_CLASS -> int32_t *)
(* pBuffer : LPSTR -> string *)
(* 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 ("WTSSetUserConfigA" wtsset-user-config-a :convention :stdcall) :int32
(p-server-name :string) ; LPSTR
(p-user-name :string) ; LPSTR
(wtsconfig-class :int32) ; WTS_CONFIG_CLASS
(p-buffer :string) ; LPSTR
(data-length :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WTSSetUserConfigA = Win32::API::More->new('WTSAPI32',
'BOOL WTSSetUserConfigA(LPCSTR pServerName, LPCSTR pUserName, int WTSConfigClass, LPCSTR pBuffer, DWORD DataLength)');
# my $ret = $WTSSetUserConfigA->Call($pServerName, $pUserName, $WTSConfigClass, $pBuffer, $DataLength);
# pServerName : LPSTR -> LPCSTR
# pUserName : LPSTR -> LPCSTR
# WTSConfigClass : WTS_CONFIG_CLASS -> int
# pBuffer : LPSTR -> LPCSTR
# DataLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f WTSSetUserConfigW (Unicode版) — 指定ユーザーの構成情報を設定する。
使用する型