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

WTSSetListenerSecurityA

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

シグネチャ

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

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

パラメーター

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

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL WTSSetListenerSecurityA(
    HANDLE hServer,   // optional
    void* pReserved,
    DWORD Reserved,
    LPSTR pListenerName,
    OBJECT_SECURITY_INFORMATION SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool WTSSetListenerSecurityA(
    IntPtr hServer,   // HANDLE optional
    IntPtr pReserved,   // void*
    uint Reserved,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string pListenerName,   // LPSTR
    uint SecurityInformation,   // OBJECT_SECURITY_INFORMATION
    IntPtr pSecurityDescriptor   // PSECURITY_DESCRIPTOR
);
<DllImport("WTSAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSSetListenerSecurityA(
    hServer As IntPtr,   ' HANDLE optional
    pReserved As IntPtr,   ' void*
    Reserved As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> pListenerName As String,   ' LPSTR
    SecurityInformation As UInteger,   ' OBJECT_SECURITY_INFORMATION
    pSecurityDescriptor As IntPtr   ' PSECURITY_DESCRIPTOR
) As Boolean
End Function
' hServer : HANDLE optional
' pReserved : void*
' Reserved : DWORD
' pListenerName : LPSTR
' SecurityInformation : OBJECT_SECURITY_INFORMATION
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
Declare PtrSafe Function WTSSetListenerSecurityA Lib "wtsapi32" ( _
    ByVal hServer As LongPtr, _
    ByVal pReserved As LongPtr, _
    ByVal Reserved As Long, _
    ByVal pListenerName As String, _
    ByVal SecurityInformation As Long, _
    ByVal pSecurityDescriptor As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WTSSetListenerSecurityA = ctypes.windll.wtsapi32.WTSSetListenerSecurityA
WTSSetListenerSecurityA.restype = wintypes.BOOL
WTSSetListenerSecurityA.argtypes = [
    wintypes.HANDLE,  # hServer : HANDLE optional
    ctypes.POINTER(None),  # pReserved : void*
    wintypes.DWORD,  # Reserved : DWORD
    wintypes.LPCSTR,  # pListenerName : LPSTR
    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')
WTSSetListenerSecurityA = Fiddle::Function.new(
  lib['WTSSetListenerSecurityA'],
  [
    Fiddle::TYPE_VOIDP,  # hServer : HANDLE optional
    Fiddle::TYPE_VOIDP,  # pReserved : void*
    -Fiddle::TYPE_INT,  # Reserved : DWORD
    Fiddle::TYPE_VOIDP,  # pListenerName : LPSTR
    -Fiddle::TYPE_INT,  # SecurityInformation : OBJECT_SECURITY_INFORMATION
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
  ],
  Fiddle::TYPE_INT)
#[link(name = "wtsapi32")]
extern "system" {
    fn WTSSetListenerSecurityA(
        hServer: *mut core::ffi::c_void,  // HANDLE optional
        pReserved: *mut (),  // void*
        Reserved: u32,  // DWORD
        pListenerName: *mut u8,  // LPSTR
        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.Ansi, SetLastError = true)]
public static extern bool WTSSetListenerSecurityA(IntPtr hServer, IntPtr pReserved, uint Reserved, [MarshalAs(UnmanagedType.LPStr)] string pListenerName, uint SecurityInformation, IntPtr pSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSSetListenerSecurityA' -Namespace Win32 -PassThru
# $api::WTSSetListenerSecurityA(hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor)
#uselib "WTSAPI32.dll"
#func global WTSSetListenerSecurityA "WTSSetListenerSecurityA" sptr, sptr, sptr, sptr, sptr, sptr
; WTSSetListenerSecurityA hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor   ; 戻り値は stat
; hServer : HANDLE optional -> "sptr"
; pReserved : void* -> "sptr"
; Reserved : DWORD -> "sptr"
; pListenerName : LPSTR -> "sptr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "sptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WTSAPI32.dll"
#cfunc global WTSSetListenerSecurityA "WTSSetListenerSecurityA" sptr, sptr, int, str, int, sptr
; res = WTSSetListenerSecurityA(hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor)
; hServer : HANDLE optional -> "sptr"
; pReserved : void* -> "sptr"
; Reserved : DWORD -> "int"
; pListenerName : LPSTR -> "str"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; BOOL WTSSetListenerSecurityA(HANDLE hServer, void* pReserved, DWORD Reserved, LPSTR pListenerName, OBJECT_SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor)
#uselib "WTSAPI32.dll"
#cfunc global WTSSetListenerSecurityA "WTSSetListenerSecurityA" intptr, intptr, int, str, int, intptr
; res = WTSSetListenerSecurityA(hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor)
; hServer : HANDLE optional -> "intptr"
; pReserved : void* -> "intptr"
; Reserved : DWORD -> "int"
; pListenerName : LPSTR -> "str"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
	procWTSSetListenerSecurityA = wtsapi32.NewProc("WTSSetListenerSecurityA")
)

// hServer (HANDLE optional), pReserved (void*), Reserved (DWORD), pListenerName (LPSTR), SecurityInformation (OBJECT_SECURITY_INFORMATION), pSecurityDescriptor (PSECURITY_DESCRIPTOR)
r1, _, err := procWTSSetListenerSecurityA.Call(
	uintptr(hServer),
	uintptr(pReserved),
	uintptr(Reserved),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pListenerName))),
	uintptr(SecurityInformation),
	uintptr(pSecurityDescriptor),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function WTSSetListenerSecurityA(
  hServer: THandle;   // HANDLE optional
  pReserved: Pointer;   // void*
  Reserved: DWORD;   // DWORD
  pListenerName: PAnsiChar;   // LPSTR
  SecurityInformation: DWORD;   // OBJECT_SECURITY_INFORMATION
  pSecurityDescriptor: THandle   // PSECURITY_DESCRIPTOR
): BOOL; stdcall;
  external 'WTSAPI32.dll' name 'WTSSetListenerSecurityA';
result := DllCall("WTSAPI32\WTSSetListenerSecurityA"
    , "Ptr", hServer   ; HANDLE optional
    , "Ptr", pReserved   ; void*
    , "UInt", Reserved   ; DWORD
    , "AStr", pListenerName   ; LPSTR
    , "UInt", SecurityInformation   ; OBJECT_SECURITY_INFORMATION
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "Int")   ; return: BOOL
●WTSSetListenerSecurityA(hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor) = DLL("WTSAPI32.dll", "bool WTSSetListenerSecurityA(void*, void*, dword, char*, dword, void*)")
# 呼び出し: WTSSetListenerSecurityA(hServer, pReserved, Reserved, pListenerName, SecurityInformation, pSecurityDescriptor)
# hServer : HANDLE optional -> "void*"
# pReserved : void* -> "void*"
# Reserved : DWORD -> "dword"
# pListenerName : LPSTR -> "char*"
# SecurityInformation : OBJECT_SECURITY_INFORMATION -> "dword"
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。