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

TreeSetNamedSecurityInfoW

関数
オブジェクトツリーにセキュリティ情報を設定し進捗を通知する(Unicode版)。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR TreeSetNamedSecurityInfoW(
    LPWSTR pObjectName,
    SE_OBJECT_TYPE ObjectType,
    OBJECT_SECURITY_INFORMATION SecurityInfo,
    PSID pOwner,   // optional
    PSID pGroup,   // optional
    ACL* pDacl,   // optional
    ACL* pSacl,   // optional
    TREE_SEC_INFO dwAction,
    FN_PROGRESS fnProgress,   // optional
    PROG_INVOKE_SETTING ProgressInvokeSetting,
    void* Args   // optional
);

パラメーター

名前方向
pObjectNameLPWSTRin
ObjectTypeSE_OBJECT_TYPEin
SecurityInfoOBJECT_SECURITY_INFORMATIONin
pOwnerPSIDinoptional
pGroupPSIDinoptional
pDaclACL*inoptional
pSaclACL*inoptional
dwActionTREE_SEC_INFOin
fnProgressFN_PROGRESSinoptional
ProgressInvokeSettingPROG_INVOKE_SETTINGin
Argsvoid*inoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR TreeSetNamedSecurityInfoW(
    LPWSTR pObjectName,
    SE_OBJECT_TYPE ObjectType,
    OBJECT_SECURITY_INFORMATION SecurityInfo,
    PSID pOwner,   // optional
    PSID pGroup,   // optional
    ACL* pDacl,   // optional
    ACL* pSacl,   // optional
    TREE_SEC_INFO dwAction,
    FN_PROGRESS fnProgress,   // optional
    PROG_INVOKE_SETTING ProgressInvokeSetting,
    void* Args   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint TreeSetNamedSecurityInfoW(
    [MarshalAs(UnmanagedType.LPWStr)] string pObjectName,   // LPWSTR
    int ObjectType,   // SE_OBJECT_TYPE
    uint SecurityInfo,   // OBJECT_SECURITY_INFORMATION
    IntPtr pOwner,   // PSID optional
    IntPtr pGroup,   // PSID optional
    IntPtr pDacl,   // ACL* optional
    IntPtr pSacl,   // ACL* optional
    uint dwAction,   // TREE_SEC_INFO
    IntPtr fnProgress,   // FN_PROGRESS optional
    int ProgressInvokeSetting,   // PROG_INVOKE_SETTING
    IntPtr Args   // void* optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function TreeSetNamedSecurityInfoW(
    <MarshalAs(UnmanagedType.LPWStr)> pObjectName As String,   ' LPWSTR
    ObjectType As Integer,   ' SE_OBJECT_TYPE
    SecurityInfo As UInteger,   ' OBJECT_SECURITY_INFORMATION
    pOwner As IntPtr,   ' PSID optional
    pGroup As IntPtr,   ' PSID optional
    pDacl As IntPtr,   ' ACL* optional
    pSacl As IntPtr,   ' ACL* optional
    dwAction As UInteger,   ' TREE_SEC_INFO
    fnProgress As IntPtr,   ' FN_PROGRESS optional
    ProgressInvokeSetting As Integer,   ' PROG_INVOKE_SETTING
    Args As IntPtr   ' void* optional
) As UInteger
End Function
' pObjectName : LPWSTR
' ObjectType : SE_OBJECT_TYPE
' SecurityInfo : OBJECT_SECURITY_INFORMATION
' pOwner : PSID optional
' pGroup : PSID optional
' pDacl : ACL* optional
' pSacl : ACL* optional
' dwAction : TREE_SEC_INFO
' fnProgress : FN_PROGRESS optional
' ProgressInvokeSetting : PROG_INVOKE_SETTING
' Args : void* optional
Declare PtrSafe Function TreeSetNamedSecurityInfoW Lib "advapi32" ( _
    ByVal pObjectName As LongPtr, _
    ByVal ObjectType As Long, _
    ByVal SecurityInfo As Long, _
    ByVal pOwner As LongPtr, _
    ByVal pGroup As LongPtr, _
    ByVal pDacl As LongPtr, _
    ByVal pSacl As LongPtr, _
    ByVal dwAction As Long, _
    ByVal fnProgress As LongPtr, _
    ByVal ProgressInvokeSetting As Long, _
    ByVal Args 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

TreeSetNamedSecurityInfoW = ctypes.windll.advapi32.TreeSetNamedSecurityInfoW
TreeSetNamedSecurityInfoW.restype = wintypes.DWORD
TreeSetNamedSecurityInfoW.argtypes = [
    wintypes.LPCWSTR,  # pObjectName : LPWSTR
    ctypes.c_int,  # ObjectType : SE_OBJECT_TYPE
    wintypes.DWORD,  # SecurityInfo : OBJECT_SECURITY_INFORMATION
    wintypes.HANDLE,  # pOwner : PSID optional
    wintypes.HANDLE,  # pGroup : PSID optional
    ctypes.c_void_p,  # pDacl : ACL* optional
    ctypes.c_void_p,  # pSacl : ACL* optional
    wintypes.DWORD,  # dwAction : TREE_SEC_INFO
    ctypes.c_void_p,  # fnProgress : FN_PROGRESS optional
    ctypes.c_int,  # ProgressInvokeSetting : PROG_INVOKE_SETTING
    ctypes.POINTER(None),  # Args : void* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
TreeSetNamedSecurityInfoW = Fiddle::Function.new(
  lib['TreeSetNamedSecurityInfoW'],
  [
    Fiddle::TYPE_VOIDP,  # pObjectName : LPWSTR
    Fiddle::TYPE_INT,  # ObjectType : SE_OBJECT_TYPE
    -Fiddle::TYPE_INT,  # SecurityInfo : OBJECT_SECURITY_INFORMATION
    Fiddle::TYPE_VOIDP,  # pOwner : PSID optional
    Fiddle::TYPE_VOIDP,  # pGroup : PSID optional
    Fiddle::TYPE_VOIDP,  # pDacl : ACL* optional
    Fiddle::TYPE_VOIDP,  # pSacl : ACL* optional
    -Fiddle::TYPE_INT,  # dwAction : TREE_SEC_INFO
    Fiddle::TYPE_VOIDP,  # fnProgress : FN_PROGRESS optional
    Fiddle::TYPE_INT,  # ProgressInvokeSetting : PROG_INVOKE_SETTING
    Fiddle::TYPE_VOIDP,  # Args : void* optional
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "advapi32")]
extern "system" {
    fn TreeSetNamedSecurityInfoW(
        pObjectName: *mut u16,  // LPWSTR
        ObjectType: i32,  // SE_OBJECT_TYPE
        SecurityInfo: u32,  // OBJECT_SECURITY_INFORMATION
        pOwner: *mut core::ffi::c_void,  // PSID optional
        pGroup: *mut core::ffi::c_void,  // PSID optional
        pDacl: *mut ACL,  // ACL* optional
        pSacl: *mut ACL,  // ACL* optional
        dwAction: u32,  // TREE_SEC_INFO
        fnProgress: *const core::ffi::c_void,  // FN_PROGRESS optional
        ProgressInvokeSetting: i32,  // PROG_INVOKE_SETTING
        Args: *mut ()  // void* optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint TreeSetNamedSecurityInfoW([MarshalAs(UnmanagedType.LPWStr)] string pObjectName, int ObjectType, uint SecurityInfo, IntPtr pOwner, IntPtr pGroup, IntPtr pDacl, IntPtr pSacl, uint dwAction, IntPtr fnProgress, int ProgressInvokeSetting, IntPtr Args);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_TreeSetNamedSecurityInfoW' -Namespace Win32 -PassThru
# $api::TreeSetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args)
#uselib "ADVAPI32.dll"
#func global TreeSetNamedSecurityInfoW "TreeSetNamedSecurityInfoW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; TreeSetNamedSecurityInfoW pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, varptr(pDacl), varptr(pSacl), dwAction, fnProgress, ProgressInvokeSetting, Args   ; 戻り値は stat
; pObjectName : LPWSTR -> "wptr"
; ObjectType : SE_OBJECT_TYPE -> "wptr"
; SecurityInfo : OBJECT_SECURITY_INFORMATION -> "wptr"
; pOwner : PSID optional -> "wptr"
; pGroup : PSID optional -> "wptr"
; pDacl : ACL* optional -> "wptr"
; pSacl : ACL* optional -> "wptr"
; dwAction : TREE_SEC_INFO -> "wptr"
; fnProgress : FN_PROGRESS optional -> "wptr"
; ProgressInvokeSetting : PROG_INVOKE_SETTING -> "wptr"
; Args : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global TreeSetNamedSecurityInfoW "TreeSetNamedSecurityInfoW" wstr, int, int, sptr, sptr, var, var, int, sptr, int, sptr
; res = TreeSetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args)
; pObjectName : LPWSTR -> "wstr"
; ObjectType : SE_OBJECT_TYPE -> "int"
; SecurityInfo : OBJECT_SECURITY_INFORMATION -> "int"
; pOwner : PSID optional -> "sptr"
; pGroup : PSID optional -> "sptr"
; pDacl : ACL* optional -> "var"
; pSacl : ACL* optional -> "var"
; dwAction : TREE_SEC_INFO -> "int"
; fnProgress : FN_PROGRESS optional -> "sptr"
; ProgressInvokeSetting : PROG_INVOKE_SETTING -> "int"
; Args : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR TreeSetNamedSecurityInfoW(LPWSTR pObjectName, SE_OBJECT_TYPE ObjectType, OBJECT_SECURITY_INFORMATION SecurityInfo, PSID pOwner, PSID pGroup, ACL* pDacl, ACL* pSacl, TREE_SEC_INFO dwAction, FN_PROGRESS fnProgress, PROG_INVOKE_SETTING ProgressInvokeSetting, void* Args)
#uselib "ADVAPI32.dll"
#cfunc global TreeSetNamedSecurityInfoW "TreeSetNamedSecurityInfoW" wstr, int, int, intptr, intptr, var, var, int, intptr, int, intptr
; res = TreeSetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args)
; pObjectName : LPWSTR -> "wstr"
; ObjectType : SE_OBJECT_TYPE -> "int"
; SecurityInfo : OBJECT_SECURITY_INFORMATION -> "int"
; pOwner : PSID optional -> "intptr"
; pGroup : PSID optional -> "intptr"
; pDacl : ACL* optional -> "var"
; pSacl : ACL* optional -> "var"
; dwAction : TREE_SEC_INFO -> "int"
; fnProgress : FN_PROGRESS optional -> "intptr"
; ProgressInvokeSetting : PROG_INVOKE_SETTING -> "int"
; Args : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procTreeSetNamedSecurityInfoW = advapi32.NewProc("TreeSetNamedSecurityInfoW")
)

// pObjectName (LPWSTR), ObjectType (SE_OBJECT_TYPE), SecurityInfo (OBJECT_SECURITY_INFORMATION), pOwner (PSID optional), pGroup (PSID optional), pDacl (ACL* optional), pSacl (ACL* optional), dwAction (TREE_SEC_INFO), fnProgress (FN_PROGRESS optional), ProgressInvokeSetting (PROG_INVOKE_SETTING), Args (void* optional)
r1, _, err := procTreeSetNamedSecurityInfoW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pObjectName))),
	uintptr(ObjectType),
	uintptr(SecurityInfo),
	uintptr(pOwner),
	uintptr(pGroup),
	uintptr(pDacl),
	uintptr(pSacl),
	uintptr(dwAction),
	uintptr(fnProgress),
	uintptr(ProgressInvokeSetting),
	uintptr(Args),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function TreeSetNamedSecurityInfoW(
  pObjectName: PWideChar;   // LPWSTR
  ObjectType: Integer;   // SE_OBJECT_TYPE
  SecurityInfo: DWORD;   // OBJECT_SECURITY_INFORMATION
  pOwner: THandle;   // PSID optional
  pGroup: THandle;   // PSID optional
  pDacl: Pointer;   // ACL* optional
  pSacl: Pointer;   // ACL* optional
  dwAction: DWORD;   // TREE_SEC_INFO
  fnProgress: Pointer;   // FN_PROGRESS optional
  ProgressInvokeSetting: Integer;   // PROG_INVOKE_SETTING
  Args: Pointer   // void* optional
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'TreeSetNamedSecurityInfoW';
result := DllCall("ADVAPI32\TreeSetNamedSecurityInfoW"
    , "WStr", pObjectName   ; LPWSTR
    , "Int", ObjectType   ; SE_OBJECT_TYPE
    , "UInt", SecurityInfo   ; OBJECT_SECURITY_INFORMATION
    , "Ptr", pOwner   ; PSID optional
    , "Ptr", pGroup   ; PSID optional
    , "Ptr", pDacl   ; ACL* optional
    , "Ptr", pSacl   ; ACL* optional
    , "UInt", dwAction   ; TREE_SEC_INFO
    , "Ptr", fnProgress   ; FN_PROGRESS optional
    , "Int", ProgressInvokeSetting   ; PROG_INVOKE_SETTING
    , "Ptr", Args   ; void* optional
    , "UInt")   ; return: WIN32_ERROR
●TreeSetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args) = DLL("ADVAPI32.dll", "dword TreeSetNamedSecurityInfoW(char*, int, dword, void*, void*, void*, void*, dword, void*, int, void*)")
# 呼び出し: TreeSetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args)
# pObjectName : LPWSTR -> "char*"
# ObjectType : SE_OBJECT_TYPE -> "int"
# SecurityInfo : OBJECT_SECURITY_INFORMATION -> "dword"
# pOwner : PSID optional -> "void*"
# pGroup : PSID optional -> "void*"
# pDacl : ACL* optional -> "void*"
# pSacl : ACL* optional -> "void*"
# dwAction : TREE_SEC_INFO -> "dword"
# fnProgress : FN_PROGRESS optional -> "void*"
# ProgressInvokeSetting : PROG_INVOKE_SETTING -> "int"
# Args : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。