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

SetSecurityInfo

関数
ハンドルで指定したオブジェクトのセキュリティ情報を設定する。
DLLADVAPI32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

WIN32_ERROR SetSecurityInfo(
    HANDLE handle,
    SE_OBJECT_TYPE ObjectType,
    OBJECT_SECURITY_INFORMATION SecurityInfo,
    PSID psidOwner,   // optional
    PSID psidGroup,   // optional
    ACL* pDacl,   // optional
    ACL* pSacl   // optional
);

パラメーター

名前方向
handleHANDLEin
ObjectTypeSE_OBJECT_TYPEin
SecurityInfoOBJECT_SECURITY_INFORMATIONin
psidOwnerPSIDinoptional
psidGroupPSIDinoptional
pDaclACL*inoptional
pSaclACL*inoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR SetSecurityInfo(
    HANDLE handle,
    SE_OBJECT_TYPE ObjectType,
    OBJECT_SECURITY_INFORMATION SecurityInfo,
    PSID psidOwner,   // optional
    PSID psidGroup,   // optional
    ACL* pDacl,   // optional
    ACL* pSacl   // optional
);
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern uint SetSecurityInfo(
    IntPtr handle,   // HANDLE
    int ObjectType,   // SE_OBJECT_TYPE
    uint SecurityInfo,   // OBJECT_SECURITY_INFORMATION
    IntPtr psidOwner,   // PSID optional
    IntPtr psidGroup,   // PSID optional
    IntPtr pDacl,   // ACL* optional
    IntPtr pSacl   // ACL* optional
);
<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function SetSecurityInfo(
    handle As IntPtr,   ' HANDLE
    ObjectType As Integer,   ' SE_OBJECT_TYPE
    SecurityInfo As UInteger,   ' OBJECT_SECURITY_INFORMATION
    psidOwner As IntPtr,   ' PSID optional
    psidGroup As IntPtr,   ' PSID optional
    pDacl As IntPtr,   ' ACL* optional
    pSacl As IntPtr   ' ACL* optional
) As UInteger
End Function
' handle : HANDLE
' ObjectType : SE_OBJECT_TYPE
' SecurityInfo : OBJECT_SECURITY_INFORMATION
' psidOwner : PSID optional
' psidGroup : PSID optional
' pDacl : ACL* optional
' pSacl : ACL* optional
Declare PtrSafe Function SetSecurityInfo Lib "advapi32" ( _
    ByVal handle As LongPtr, _
    ByVal ObjectType As Long, _
    ByVal SecurityInfo As Long, _
    ByVal psidOwner As LongPtr, _
    ByVal psidGroup As LongPtr, _
    ByVal pDacl As LongPtr, _
    ByVal pSacl As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetSecurityInfo = ctypes.windll.advapi32.SetSecurityInfo
SetSecurityInfo.restype = wintypes.DWORD
SetSecurityInfo.argtypes = [
    wintypes.HANDLE,  # handle : HANDLE
    ctypes.c_int,  # ObjectType : SE_OBJECT_TYPE
    wintypes.DWORD,  # SecurityInfo : OBJECT_SECURITY_INFORMATION
    wintypes.HANDLE,  # psidOwner : PSID optional
    wintypes.HANDLE,  # psidGroup : PSID optional
    ctypes.c_void_p,  # pDacl : ACL* optional
    ctypes.c_void_p,  # pSacl : ACL* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
SetSecurityInfo = Fiddle::Function.new(
  lib['SetSecurityInfo'],
  [
    Fiddle::TYPE_VOIDP,  # handle : HANDLE
    Fiddle::TYPE_INT,  # ObjectType : SE_OBJECT_TYPE
    -Fiddle::TYPE_INT,  # SecurityInfo : OBJECT_SECURITY_INFORMATION
    Fiddle::TYPE_VOIDP,  # psidOwner : PSID optional
    Fiddle::TYPE_VOIDP,  # psidGroup : PSID optional
    Fiddle::TYPE_VOIDP,  # pDacl : ACL* optional
    Fiddle::TYPE_VOIDP,  # pSacl : ACL* optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SetSecurityInfo(
        handle: *mut core::ffi::c_void,  // HANDLE
        ObjectType: i32,  // SE_OBJECT_TYPE
        SecurityInfo: u32,  // OBJECT_SECURITY_INFORMATION
        psidOwner: *mut core::ffi::c_void,  // PSID optional
        psidGroup: *mut core::ffi::c_void,  // PSID optional
        pDacl: *mut ACL,  // ACL* optional
        pSacl: *mut ACL  // ACL* optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern uint SetSecurityInfo(IntPtr handle, int ObjectType, uint SecurityInfo, IntPtr psidOwner, IntPtr psidGroup, IntPtr pDacl, IntPtr pSacl);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetSecurityInfo' -Namespace Win32 -PassThru
# $api::SetSecurityInfo(handle, ObjectType, SecurityInfo, psidOwner, psidGroup, pDacl, pSacl)
#uselib "ADVAPI32.dll"
#func global SetSecurityInfo "SetSecurityInfo" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetSecurityInfo handle, ObjectType, SecurityInfo, psidOwner, psidGroup, varptr(pDacl), varptr(pSacl)   ; 戻り値は stat
; handle : HANDLE -> "sptr"
; ObjectType : SE_OBJECT_TYPE -> "sptr"
; SecurityInfo : OBJECT_SECURITY_INFORMATION -> "sptr"
; psidOwner : PSID optional -> "sptr"
; psidGroup : PSID optional -> "sptr"
; pDacl : ACL* optional -> "sptr"
; pSacl : ACL* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityInfo "SetSecurityInfo" sptr, int, int, sptr, sptr, var, var
; res = SetSecurityInfo(handle, ObjectType, SecurityInfo, psidOwner, psidGroup, pDacl, pSacl)
; handle : HANDLE -> "sptr"
; ObjectType : SE_OBJECT_TYPE -> "int"
; SecurityInfo : OBJECT_SECURITY_INFORMATION -> "int"
; psidOwner : PSID optional -> "sptr"
; psidGroup : PSID optional -> "sptr"
; pDacl : ACL* optional -> "var"
; pSacl : ACL* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR SetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType, OBJECT_SECURITY_INFORMATION SecurityInfo, PSID psidOwner, PSID psidGroup, ACL* pDacl, ACL* pSacl)
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityInfo "SetSecurityInfo" intptr, int, int, intptr, intptr, var, var
; res = SetSecurityInfo(handle, ObjectType, SecurityInfo, psidOwner, psidGroup, pDacl, pSacl)
; handle : HANDLE -> "intptr"
; ObjectType : SE_OBJECT_TYPE -> "int"
; SecurityInfo : OBJECT_SECURITY_INFORMATION -> "int"
; psidOwner : PSID optional -> "intptr"
; psidGroup : PSID optional -> "intptr"
; pDacl : ACL* optional -> "var"
; pSacl : ACL* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSetSecurityInfo = advapi32.NewProc("SetSecurityInfo")
)

// handle (HANDLE), ObjectType (SE_OBJECT_TYPE), SecurityInfo (OBJECT_SECURITY_INFORMATION), psidOwner (PSID optional), psidGroup (PSID optional), pDacl (ACL* optional), pSacl (ACL* optional)
r1, _, err := procSetSecurityInfo.Call(
	uintptr(handle),
	uintptr(ObjectType),
	uintptr(SecurityInfo),
	uintptr(psidOwner),
	uintptr(psidGroup),
	uintptr(pDacl),
	uintptr(pSacl),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function SetSecurityInfo(
  handle: THandle;   // HANDLE
  ObjectType: Integer;   // SE_OBJECT_TYPE
  SecurityInfo: DWORD;   // OBJECT_SECURITY_INFORMATION
  psidOwner: THandle;   // PSID optional
  psidGroup: THandle;   // PSID optional
  pDacl: Pointer;   // ACL* optional
  pSacl: Pointer   // ACL* optional
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'SetSecurityInfo';
result := DllCall("ADVAPI32\SetSecurityInfo"
    , "Ptr", handle   ; HANDLE
    , "Int", ObjectType   ; SE_OBJECT_TYPE
    , "UInt", SecurityInfo   ; OBJECT_SECURITY_INFORMATION
    , "Ptr", psidOwner   ; PSID optional
    , "Ptr", psidGroup   ; PSID optional
    , "Ptr", pDacl   ; ACL* optional
    , "Ptr", pSacl   ; ACL* optional
    , "UInt")   ; return: WIN32_ERROR
●SetSecurityInfo(handle, ObjectType, SecurityInfo, psidOwner, psidGroup, pDacl, pSacl) = DLL("ADVAPI32.dll", "dword SetSecurityInfo(void*, int, dword, void*, void*, void*, void*)")
# 呼び出し: SetSecurityInfo(handle, ObjectType, SecurityInfo, psidOwner, psidGroup, pDacl, pSacl)
# handle : HANDLE -> "void*"
# ObjectType : SE_OBJECT_TYPE -> "int"
# SecurityInfo : OBJECT_SECURITY_INFORMATION -> "dword"
# psidOwner : PSID optional -> "void*"
# psidGroup : PSID optional -> "void*"
# pDacl : ACL* optional -> "void*"
# pSacl : ACL* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。