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

TreeSetNamedSecurityInfoA

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

シグネチャ

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

WIN32_ERROR TreeSetNamedSecurityInfoA(
    LPSTR 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
);

パラメーター

名前方向
pObjectNameLPSTRin
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  (ANSI / -A)
#include <windows.h>

WIN32_ERROR TreeSetNamedSecurityInfoA(
    LPSTR 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.Ansi, ExactSpelling = true)]
static extern uint TreeSetNamedSecurityInfoA(
    [MarshalAs(UnmanagedType.LPStr)] string pObjectName,   // LPSTR
    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.Ansi, ExactSpelling:=True)>
Public Shared Function TreeSetNamedSecurityInfoA(
    <MarshalAs(UnmanagedType.LPStr)> pObjectName As String,   ' LPSTR
    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 : LPSTR
' 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 TreeSetNamedSecurityInfoA Lib "advapi32" ( _
    ByVal pObjectName As String, _
    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
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

TreeSetNamedSecurityInfoA = ctypes.windll.advapi32.TreeSetNamedSecurityInfoA
TreeSetNamedSecurityInfoA.restype = wintypes.DWORD
TreeSetNamedSecurityInfoA.argtypes = [
    wintypes.LPCSTR,  # pObjectName : LPSTR
    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')
TreeSetNamedSecurityInfoA = Fiddle::Function.new(
  lib['TreeSetNamedSecurityInfoA'],
  [
    Fiddle::TYPE_VOIDP,  # pObjectName : LPSTR
    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)
#[link(name = "advapi32")]
extern "system" {
    fn TreeSetNamedSecurityInfoA(
        pObjectName: *mut u8,  // LPSTR
        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.Ansi)]
public static extern uint TreeSetNamedSecurityInfoA([MarshalAs(UnmanagedType.LPStr)] 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_TreeSetNamedSecurityInfoA' -Namespace Win32 -PassThru
# $api::TreeSetNamedSecurityInfoA(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args)
#uselib "ADVAPI32.dll"
#func global TreeSetNamedSecurityInfoA "TreeSetNamedSecurityInfoA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; TreeSetNamedSecurityInfoA pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, varptr(pDacl), varptr(pSacl), dwAction, fnProgress, ProgressInvokeSetting, Args   ; 戻り値は stat
; pObjectName : LPSTR -> "sptr"
; ObjectType : SE_OBJECT_TYPE -> "sptr"
; SecurityInfo : OBJECT_SECURITY_INFORMATION -> "sptr"
; pOwner : PSID optional -> "sptr"
; pGroup : PSID optional -> "sptr"
; pDacl : ACL* optional -> "sptr"
; pSacl : ACL* optional -> "sptr"
; dwAction : TREE_SEC_INFO -> "sptr"
; fnProgress : FN_PROGRESS optional -> "sptr"
; ProgressInvokeSetting : PROG_INVOKE_SETTING -> "sptr"
; Args : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global TreeSetNamedSecurityInfoA "TreeSetNamedSecurityInfoA" str, int, int, sptr, sptr, var, var, int, sptr, int, sptr
; res = TreeSetNamedSecurityInfoA(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args)
; pObjectName : LPSTR -> "str"
; 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 TreeSetNamedSecurityInfoA(LPSTR 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 TreeSetNamedSecurityInfoA "TreeSetNamedSecurityInfoA" str, int, int, intptr, intptr, var, var, int, intptr, int, intptr
; res = TreeSetNamedSecurityInfoA(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args)
; pObjectName : LPSTR -> "str"
; 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")
	procTreeSetNamedSecurityInfoA = advapi32.NewProc("TreeSetNamedSecurityInfoA")
)

// pObjectName (LPSTR), 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 := procTreeSetNamedSecurityInfoA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(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 TreeSetNamedSecurityInfoA(
  pObjectName: PAnsiChar;   // LPSTR
  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 'TreeSetNamedSecurityInfoA';
result := DllCall("ADVAPI32\TreeSetNamedSecurityInfoA"
    , "AStr", pObjectName   ; LPSTR
    , "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
●TreeSetNamedSecurityInfoA(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args) = DLL("ADVAPI32.dll", "dword TreeSetNamedSecurityInfoA(char*, int, dword, void*, void*, void*, void*, dword, void*, int, void*)")
# 呼び出し: TreeSetNamedSecurityInfoA(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, dwAction, fnProgress, ProgressInvokeSetting, Args)
# pObjectName : LPSTR -> "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)。