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

WTSSetListenerSecurityW

関数
指定リスナーのセキュリティ記述子を設定する。
DLLWTSAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 7 以降

シグネチャ

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

BOOL WTSSetListenerSecurityW(
    HANDLE hServer,   // optional
    void* pReserved,
    DWORD Reserved,
    LPWSTR pListenerName,
    OBJECT_SECURITY_INFORMATION SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);

パラメーター

名前方向
hServerHANDLEinoptional
pReservedvoid*in
ReservedDWORDin
pListenerNameLPWSTRin
SecurityInformationOBJECT_SECURITY_INFORMATIONin
pSecurityDescriptorPSECURITY_DESCRIPTORin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL WTSSetListenerSecurityW(
    HANDLE hServer,   // optional
    void* pReserved,
    DWORD Reserved,
    LPWSTR pListenerName,
    OBJECT_SECURITY_INFORMATION SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool WTSSetListenerSecurityW(
    IntPtr hServer,   // HANDLE optional
    IntPtr pReserved,   // void*
    uint Reserved,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string pListenerName,   // LPWSTR
    uint SecurityInformation,   // OBJECT_SECURITY_INFORMATION
    IntPtr pSecurityDescriptor   // PSECURITY_DESCRIPTOR
);
<DllImport("WTSAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSSetListenerSecurityW(
    hServer As IntPtr,   ' HANDLE optional
    pReserved As IntPtr,   ' void*
    Reserved As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pListenerName As String,   ' LPWSTR
    SecurityInformation As UInteger,   ' OBJECT_SECURITY_INFORMATION
    pSecurityDescriptor As IntPtr   ' PSECURITY_DESCRIPTOR
) As Boolean
End Function
' hServer : HANDLE optional
' pReserved : void*
' Reserved : DWORD
' pListenerName : LPWSTR
' SecurityInformation : OBJECT_SECURITY_INFORMATION
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
Declare PtrSafe Function WTSSetListenerSecurityW Lib "wtsapi32" ( _
    ByVal hServer As LongPtr, _
    ByVal pReserved As LongPtr, _
    ByVal Reserved As Long, _
    ByVal pListenerName As LongPtr, _
    ByVal SecurityInformation As Long, _
    ByVal pSecurityDescriptor As LongPtr) 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

WTSSetListenerSecurityW = ctypes.windll.wtsapi32.WTSSetListenerSecurityW
WTSSetListenerSecurityW.restype = wintypes.BOOL
WTSSetListenerSecurityW.argtypes = [
    wintypes.HANDLE,  # hServer : HANDLE optional
    ctypes.POINTER(None),  # pReserved : void*
    wintypes.DWORD,  # Reserved : DWORD
    wintypes.LPCWSTR,  # pListenerName : LPWSTR
    wintypes.DWORD,  # SecurityInformation : OBJECT_SECURITY_INFORMATION
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WTSAPI32.dll')
WTSSetListenerSecurityW = Fiddle::Function.new(
  lib['WTSSetListenerSecurityW'],
  [
    Fiddle::TYPE_VOIDP,  # hServer : HANDLE optional
    Fiddle::TYPE_VOIDP,  # pReserved : void*
    -Fiddle::TYPE_INT,  # Reserved : DWORD
    Fiddle::TYPE_VOIDP,  # pListenerName : LPWSTR
    -Fiddle::TYPE_INT,  # SecurityInformation : OBJECT_SECURITY_INFORMATION
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wtsapi32")]
extern "system" {
    fn WTSSetListenerSecurityW(
        hServer: *mut core::ffi::c_void,  // HANDLE optional
        pReserved: *mut (),  // void*
        Reserved: u32,  // DWORD
        pListenerName: *mut u16,  // LPWSTR
        SecurityInformation: u32,  // OBJECT_SECURITY_INFORMATION
        pSecurityDescriptor: *mut core::ffi::c_void  // PSECURITY_DESCRIPTOR
    ) -> 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 WTSSetListenerSecurityW(IntPtr hServer, IntPtr pReserved, uint Reserved, [MarshalAs(UnmanagedType.LPWStr)] string pListenerName, uint SecurityInformation, IntPtr pSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSSetListenerSecurityW' -Namespace Win32 -PassThru
# $api::WTSSetListenerSecurityW(hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor)
#uselib "WTSAPI32.dll"
#func global WTSSetListenerSecurityW "WTSSetListenerSecurityW" wptr, wptr, wptr, wptr, wptr, wptr
; WTSSetListenerSecurityW hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor   ; 戻り値は stat
; hServer : HANDLE optional -> "wptr"
; pReserved : void* -> "wptr"
; Reserved : DWORD -> "wptr"
; pListenerName : LPWSTR -> "wptr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "wptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WTSAPI32.dll"
#cfunc global WTSSetListenerSecurityW "WTSSetListenerSecurityW" sptr, sptr, int, wstr, int, sptr
; res = WTSSetListenerSecurityW(hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor)
; hServer : HANDLE optional -> "sptr"
; pReserved : void* -> "sptr"
; Reserved : DWORD -> "int"
; pListenerName : LPWSTR -> "wstr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; BOOL WTSSetListenerSecurityW(HANDLE hServer, void* pReserved, DWORD Reserved, LPWSTR pListenerName, OBJECT_SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor)
#uselib "WTSAPI32.dll"
#cfunc global WTSSetListenerSecurityW "WTSSetListenerSecurityW" intptr, intptr, int, wstr, int, intptr
; res = WTSSetListenerSecurityW(hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor)
; hServer : HANDLE optional -> "intptr"
; pReserved : void* -> "intptr"
; Reserved : DWORD -> "int"
; pListenerName : LPWSTR -> "wstr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
	procWTSSetListenerSecurityW = wtsapi32.NewProc("WTSSetListenerSecurityW")
)

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