Win32 API 日本語リファレンス
ホームSecurity › SetSecurityDescriptorControl

SetSecurityDescriptorControl

関数
セキュリティ記述子の制御ビットを設定する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// ADVAPI32.dll
#include <windows.h>

BOOL SetSecurityDescriptorControl(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
    SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
);

パラメーター

名前方向
pSecurityDescriptorPSECURITY_DESCRIPTORin
ControlBitsOfInterestSECURITY_DESCRIPTOR_CONTROLin
ControlBitsToSetSECURITY_DESCRIPTOR_CONTROLin

戻り値の型: BOOL

各言語での呼び出し定義

// ADVAPI32.dll
#include <windows.h>

BOOL SetSecurityDescriptorControl(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
    SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetSecurityDescriptorControl(
    IntPtr pSecurityDescriptor,   // PSECURITY_DESCRIPTOR
    ushort ControlBitsOfInterest,   // SECURITY_DESCRIPTOR_CONTROL
    ushort ControlBitsToSet   // SECURITY_DESCRIPTOR_CONTROL
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetSecurityDescriptorControl(
    pSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR
    ControlBitsOfInterest As UShort,   ' SECURITY_DESCRIPTOR_CONTROL
    ControlBitsToSet As UShort   ' SECURITY_DESCRIPTOR_CONTROL
) As Boolean
End Function
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
' ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL
' ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL
Declare PtrSafe Function SetSecurityDescriptorControl Lib "advapi32" ( _
    ByVal pSecurityDescriptor As LongPtr, _
    ByVal ControlBitsOfInterest As Integer, _
    ByVal ControlBitsToSet As Integer) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetSecurityDescriptorControl = ctypes.windll.advapi32.SetSecurityDescriptorControl
SetSecurityDescriptorControl.restype = wintypes.BOOL
SetSecurityDescriptorControl.argtypes = [
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    ctypes.c_ushort,  # ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL
    ctypes.c_ushort,  # ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
SetSecurityDescriptorControl = Fiddle::Function.new(
  lib['SetSecurityDescriptorControl'],
  [
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    -Fiddle::TYPE_SHORT,  # ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL
    -Fiddle::TYPE_SHORT,  # ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SetSecurityDescriptorControl(
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR
        ControlBitsOfInterest: u16,  // SECURITY_DESCRIPTOR_CONTROL
        ControlBitsToSet: u16  // SECURITY_DESCRIPTOR_CONTROL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool SetSecurityDescriptorControl(IntPtr pSecurityDescriptor, ushort ControlBitsOfInterest, ushort ControlBitsToSet);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetSecurityDescriptorControl' -Namespace Win32 -PassThru
# $api::SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet)
#uselib "ADVAPI32.dll"
#func global SetSecurityDescriptorControl "SetSecurityDescriptorControl" sptr, sptr, sptr
; SetSecurityDescriptorControl pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet   ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> "sptr"
; ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorControl "SetSecurityDescriptorControl" sptr, int, int
; res = SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> "int"
; ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> "int"
; BOOL SetSecurityDescriptorControl(PSECURITY_DESCRIPTOR pSecurityDescriptor, SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest, SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet)
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorControl "SetSecurityDescriptorControl" intptr, int, int
; res = SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
; ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> "int"
; ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSetSecurityDescriptorControl = advapi32.NewProc("SetSecurityDescriptorControl")
)

// pSecurityDescriptor (PSECURITY_DESCRIPTOR), ControlBitsOfInterest (SECURITY_DESCRIPTOR_CONTROL), ControlBitsToSet (SECURITY_DESCRIPTOR_CONTROL)
r1, _, err := procSetSecurityDescriptorControl.Call(
	uintptr(pSecurityDescriptor),
	uintptr(ControlBitsOfInterest),
	uintptr(ControlBitsToSet),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetSecurityDescriptorControl(
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  ControlBitsOfInterest: Word;   // SECURITY_DESCRIPTOR_CONTROL
  ControlBitsToSet: Word   // SECURITY_DESCRIPTOR_CONTROL
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'SetSecurityDescriptorControl';
result := DllCall("ADVAPI32\SetSecurityDescriptorControl"
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "UShort", ControlBitsOfInterest   ; SECURITY_DESCRIPTOR_CONTROL
    , "UShort", ControlBitsToSet   ; SECURITY_DESCRIPTOR_CONTROL
    , "Int")   ; return: BOOL
●SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet) = DLL("ADVAPI32.dll", "bool SetSecurityDescriptorControl(void*, int, int)")
# 呼び出し: SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> "int"
# ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。