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

TreeResetNamedSecurityInfoW

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

シグネチャ

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

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

パラメーター

名前方向説明
pObjectNameLPWSTRin更新されたセキュリティ情報を受け取るオブジェクトのルートノードオブジェクトの名前を指定する、null 終端文字列へのポインターです。サポートされるオブジェクトはレジストリキーとファイルオブジェクトです。オブジェクトの種類ごとの文字列形式の説明については、 SE_OBJECT_TYPE を参照してください。
ObjectTypeSE_OBJECT_TYPEinpObjectName パラメーターで指定されたオブジェクトの種類を示す、SE_OBJECT_TYPE 列挙体の値です。サポートされる値は、レジストリキーの場合は SE_REGISTRY_KEY、ファイルオブジェクトの場合は SE_FILE_OBJECT です。
SecurityInfoOBJECT_SECURITY_INFORMATIONinリセットするセキュリティ情報の種類を示す ビットフラグのセットです。このパラメーターには、 SECURITY_INFORMATION ビットフラグの組み合わせを指定できます。
pOwnerPSIDinoptionalオブジェクトの所有者を識別する SID 構造体へのポインターです。SID は、セキュリティ記述子の所有者 SID として割り当て可能なものでなければなりません。SecurityInfo パラメーターには OWNER_SECURITY_INFORMATION フラグを含める必要があります。所有者を設定するには、呼び出し元はルートオブジェクトを含む各オブジェクトに対して WRITE_OWNER アクセス権を持っている必要があります。所有者 SID を設定しない場合、このパラメーターは NULL にできます。
pGroupPSIDinoptionalオブジェクトのプライマリグループを識別する SID 構造体へのポインターです。SecurityInfo パラメーターには GROUP_SECURITY_INFORMATION フラグを含める必要があります。グループを設定するには、呼び出し元はルートオブジェクトを含む各オブジェクトに対して WRITE_OWNER アクセス権を持っている必要があります。プライマリグループ SID を設定しない場合、このパラメーターは NULL にできます。
pDaclACL*inoptionalリセット対象のオブジェクトの新しい DACL を表す アクセス制御リスト(ACL)構造体へのポインターです。SecurityInfo パラメーターには DACL_SECURITY_INFORMATION フラグを含める必要があります。呼び出し元はルートオブジェクトを含む各オブジェクトに対して READ_CONTROL および WRITE_DAC アクセス権を持っている必要があります。DACL を設定しない場合、このパラメーターは NULL にできます。
pSaclACL*inoptionalリセット対象のオブジェクトの新しい SACL を表す ACL 構造体へのポインターです。SecurityInfo パラメーターには、SACL_SECURITY_INFORMATIONLABEL_SECURITY_INFORMATIONATTRIBUTE_SECURITY_INFORMATIONSCOPE_SECURITY_INFORMATIONBACKUP_SECURITY_INFORMATION のいずれかのフラグを含める必要があります。SACL_SECURITY_INFORMATION または SCOPE_SECURITY_INFORMATION を設定する場合、呼び出し元は SE_SECURITY_NAME 特権を有効にしておく必要があります。SACL を設定しない場合、このパラメーターは NULL にできます。
KeepExplicitBOOLinサブツリーに対して明示的に定義された ACE を保持するか削除するかを定義するブール値です。KeepExplicitTRUE の場合、各サブツリーの DACL および SACL について明示的に定義された ACE は保持され、継承された ACE は pDacl および pSacl からの継承 ACE に置き換えられます。KeepExplicitFALSE の場合、各サブツリーの DACL および SACL について明示的に定義された ACE は、継承された ACE が pDacl および pSacl からの継承 ACE に置き換えられる前に削除されます。
fnProgressFN_PROGRESSinoptional

TreeResetNamedSecurityInfo 関数の進行状況を追跡するために使用される関数へのポインターです。進行状況関数のプロトタイプは次のとおりです。

#include <windows.h>
#include <Aclapi.h>

typedef VOID (*FN_PROGRESS) (
  IN LPWSTR pObjectName,              // Name of object just processed
  IN DWORD Status,                    // Status of operation on object
  IN OUT PPROG_INVOKE_SETTING pInvokeSetting, // When to set
  IN PVOID Args,                      // Caller specific data
  IN BOOL SecuritySet                 // Whether security was set
);

進行状況関数は、ノードが処理される際に進行状況とエラー情報を呼び出し元に提供します。呼び出し元は fnProgress で進行状況関数を指定し、ツリー操作の実行中に TreeResetNamedSecurityInfo は最後に処理されたオブジェクトの名前、その操作のエラー状態、および現在の PROG_INVOKE_SETTING 値を渡します。呼び出し元は pInvokeSetting を使用して PROG_INVOKE_SETTING 値を変更できます。

進行状況関数を使用しない場合は、このパラメーターを NULL に設定します。

ProgressInvokeSettingPROG_INVOKE_SETTINGin進行状況関数の初期設定を指定する PROG_INVOKE_SETTING 列挙体の値です。
Argsvoid*inoptional呼び出し元が指定する進行状況関数の引数を表す VOID へのポインターです。

戻り値の型: WIN32_ERROR

公式ドキュメント

指定したオブジェクトツリーのセキュリティ記述子内の、指定したセキュリティ情報をリセットします。(Unicode)

戻り値

関数が成功すると、ERROR_SUCCESS を返します。

関数が失敗すると、WinError.h で定義されたエラーコードを返します。

解説(Remarks)

所有者、グループ、DACL、SACL に NULL を設定することは、この関数ではサポートされていません。

要求された所有者、グループ、DACL、SACL の更新を行うために必要な特権とアクセス許可を呼び出し元が持っていない場合、いずれの更新も実行されません。

この関数は TreeSetNamedSecurityInfo 関数に似ています。

メモ

aclapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして TreeResetNamedSecurityInfo を定義しています。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在して使用すると、不一致が生じてコンパイルエラーやランタイムエラーを引き起こす可能性があります。詳細については、関数プロトタイプの規約を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

WIN32_ERROR TreeResetNamedSecurityInfoW(
    LPWSTR pObjectName,
    SE_OBJECT_TYPE ObjectType,
    OBJECT_SECURITY_INFORMATION SecurityInfo,
    PSID pOwner,   // optional
    PSID pGroup,   // optional
    ACL* pDacl,   // optional
    ACL* pSacl,   // optional
    BOOL KeepExplicit,
    FN_PROGRESS fnProgress,   // optional
    PROG_INVOKE_SETTING ProgressInvokeSetting,
    void* Args   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint TreeResetNamedSecurityInfoW(
    [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
    bool KeepExplicit,   // BOOL
    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 TreeResetNamedSecurityInfoW(
    <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
    KeepExplicit As Boolean,   ' BOOL
    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
' KeepExplicit : BOOL
' fnProgress : FN_PROGRESS optional
' ProgressInvokeSetting : PROG_INVOKE_SETTING
' Args : void* optional
Declare PtrSafe Function TreeResetNamedSecurityInfoW 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 KeepExplicit 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

TreeResetNamedSecurityInfoW = ctypes.windll.advapi32.TreeResetNamedSecurityInfoW
TreeResetNamedSecurityInfoW.restype = wintypes.DWORD
TreeResetNamedSecurityInfoW.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.BOOL,  # KeepExplicit : BOOL
    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')
TreeResetNamedSecurityInfoW = Fiddle::Function.new(
  lib['TreeResetNamedSecurityInfoW'],
  [
    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,  # KeepExplicit : BOOL
    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 TreeResetNamedSecurityInfoW(
        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
        KeepExplicit: i32,  // BOOL
        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 TreeResetNamedSecurityInfoW([MarshalAs(UnmanagedType.LPWStr)] string pObjectName, int ObjectType, uint SecurityInfo, IntPtr pOwner, IntPtr pGroup, IntPtr pDacl, IntPtr pSacl, bool KeepExplicit, IntPtr fnProgress, int ProgressInvokeSetting, IntPtr Args);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_TreeResetNamedSecurityInfoW' -Namespace Win32 -PassThru
# $api::TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, fnProgress, ProgressInvokeSetting, Args)
#uselib "ADVAPI32.dll"
#func global TreeResetNamedSecurityInfoW "TreeResetNamedSecurityInfoW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; TreeResetNamedSecurityInfoW pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, varptr(pDacl), varptr(pSacl), KeepExplicit, 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"
; KeepExplicit : BOOL -> "wptr"
; fnProgress : FN_PROGRESS optional -> "wptr"
; ProgressInvokeSetting : PROG_INVOKE_SETTING -> "wptr"
; Args : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global TreeResetNamedSecurityInfoW "TreeResetNamedSecurityInfoW" wstr, int, int, sptr, sptr, var, var, int, sptr, int, sptr
; res = TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, 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"
; KeepExplicit : BOOL -> "int"
; fnProgress : FN_PROGRESS optional -> "sptr"
; ProgressInvokeSetting : PROG_INVOKE_SETTING -> "int"
; Args : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR TreeResetNamedSecurityInfoW(LPWSTR pObjectName, SE_OBJECT_TYPE ObjectType, OBJECT_SECURITY_INFORMATION SecurityInfo, PSID pOwner, PSID pGroup, ACL* pDacl, ACL* pSacl, BOOL KeepExplicit, FN_PROGRESS fnProgress, PROG_INVOKE_SETTING ProgressInvokeSetting, void* Args)
#uselib "ADVAPI32.dll"
#cfunc global TreeResetNamedSecurityInfoW "TreeResetNamedSecurityInfoW" wstr, int, int, intptr, intptr, var, var, int, intptr, int, intptr
; res = TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, 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"
; KeepExplicit : BOOL -> "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")
	procTreeResetNamedSecurityInfoW = advapi32.NewProc("TreeResetNamedSecurityInfoW")
)

// pObjectName (LPWSTR), ObjectType (SE_OBJECT_TYPE), SecurityInfo (OBJECT_SECURITY_INFORMATION), pOwner (PSID optional), pGroup (PSID optional), pDacl (ACL* optional), pSacl (ACL* optional), KeepExplicit (BOOL), fnProgress (FN_PROGRESS optional), ProgressInvokeSetting (PROG_INVOKE_SETTING), Args (void* optional)
r1, _, err := procTreeResetNamedSecurityInfoW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pObjectName))),
	uintptr(ObjectType),
	uintptr(SecurityInfo),
	uintptr(pOwner),
	uintptr(pGroup),
	uintptr(pDacl),
	uintptr(pSacl),
	uintptr(KeepExplicit),
	uintptr(fnProgress),
	uintptr(ProgressInvokeSetting),
	uintptr(Args),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function TreeResetNamedSecurityInfoW(
  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
  KeepExplicit: BOOL;   // BOOL
  fnProgress: Pointer;   // FN_PROGRESS optional
  ProgressInvokeSetting: Integer;   // PROG_INVOKE_SETTING
  Args: Pointer   // void* optional
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'TreeResetNamedSecurityInfoW';
result := DllCall("ADVAPI32\TreeResetNamedSecurityInfoW"
    , "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
    , "Int", KeepExplicit   ; BOOL
    , "Ptr", fnProgress   ; FN_PROGRESS optional
    , "Int", ProgressInvokeSetting   ; PROG_INVOKE_SETTING
    , "Ptr", Args   ; void* optional
    , "UInt")   ; return: WIN32_ERROR
●TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, fnProgress, ProgressInvokeSetting, Args) = DLL("ADVAPI32.dll", "dword TreeResetNamedSecurityInfoW(char*, int, dword, void*, void*, void*, void*, bool, void*, int, void*)")
# 呼び出し: TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, 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*"
# KeepExplicit : BOOL -> "bool"
# 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 版の利用を推奨。
const std = @import("std");

extern "advapi32" fn TreeResetNamedSecurityInfoW(
    pObjectName: [*c]const u16, // LPWSTR
    ObjectType: i32, // SE_OBJECT_TYPE
    SecurityInfo: u32, // OBJECT_SECURITY_INFORMATION
    pOwner: ?*anyopaque, // PSID optional
    pGroup: ?*anyopaque, // PSID optional
    pDacl: [*c]ACL, // ACL* optional
    pSacl: [*c]ACL, // ACL* optional
    KeepExplicit: i32, // BOOL
    fnProgress: ?*anyopaque, // FN_PROGRESS optional
    ProgressInvokeSetting: i32, // PROG_INVOKE_SETTING
    Args: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc TreeResetNamedSecurityInfoW(
    pObjectName: WideCString,  # LPWSTR
    ObjectType: int32,  # SE_OBJECT_TYPE
    SecurityInfo: uint32,  # OBJECT_SECURITY_INFORMATION
    pOwner: pointer,  # PSID optional
    pGroup: pointer,  # PSID optional
    pDacl: ptr ACL,  # ACL* optional
    pSacl: ptr ACL,  # ACL* optional
    KeepExplicit: int32,  # BOOL
    fnProgress: pointer,  # FN_PROGRESS optional
    ProgressInvokeSetting: int32,  # PROG_INVOKE_SETTING
    Args: pointer  # void* optional
): uint32 {.importc: "TreeResetNamedSecurityInfoW", stdcall, dynlib: "ADVAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "advapi32");
extern(Windows)
uint TreeResetNamedSecurityInfoW(
    const(wchar)* pObjectName,   // LPWSTR
    int ObjectType,   // SE_OBJECT_TYPE
    uint SecurityInfo,   // OBJECT_SECURITY_INFORMATION
    void* pOwner,   // PSID optional
    void* pGroup,   // PSID optional
    ACL* pDacl,   // ACL* optional
    ACL* pSacl,   // ACL* optional
    int KeepExplicit,   // BOOL
    void* fnProgress,   // FN_PROGRESS optional
    int ProgressInvokeSetting,   // PROG_INVOKE_SETTING
    void* Args   // void* optional
);
ccall((:TreeResetNamedSecurityInfoW, "ADVAPI32.dll"), stdcall, UInt32,
      (Cwstring, Int32, UInt32, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{ACL}, Ptr{ACL}, Int32, Ptr{Cvoid}, Int32, Ptr{Cvoid}),
      pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, fnProgress, ProgressInvokeSetting, Args)
# pObjectName : LPWSTR -> Cwstring
# ObjectType : SE_OBJECT_TYPE -> Int32
# SecurityInfo : OBJECT_SECURITY_INFORMATION -> UInt32
# pOwner : PSID optional -> Ptr{Cvoid}
# pGroup : PSID optional -> Ptr{Cvoid}
# pDacl : ACL* optional -> Ptr{ACL}
# pSacl : ACL* optional -> Ptr{ACL}
# KeepExplicit : BOOL -> Int32
# fnProgress : FN_PROGRESS optional -> Ptr{Cvoid}
# ProgressInvokeSetting : PROG_INVOKE_SETTING -> Int32
# Args : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t TreeResetNamedSecurityInfoW(
    const uint16_t* pObjectName,
    int32_t ObjectType,
    uint32_t SecurityInfo,
    void* pOwner,
    void* pGroup,
    void* pDacl,
    void* pSacl,
    int32_t KeepExplicit,
    void* fnProgress,
    int32_t ProgressInvokeSetting,
    void* Args);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, fnProgress, ProgressInvokeSetting, Args)
-- pObjectName : LPWSTR
-- ObjectType : SE_OBJECT_TYPE
-- SecurityInfo : OBJECT_SECURITY_INFORMATION
-- pOwner : PSID optional
-- pGroup : PSID optional
-- pDacl : ACL* optional
-- pSacl : ACL* optional
-- KeepExplicit : BOOL
-- fnProgress : FN_PROGRESS optional
-- ProgressInvokeSetting : PROG_INVOKE_SETTING
-- Args : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const TreeResetNamedSecurityInfoW = lib.func('__stdcall', 'TreeResetNamedSecurityInfoW', 'uint32_t', ['str16', 'int32_t', 'uint32_t', 'void *', 'void *', 'void *', 'void *', 'int32_t', 'void *', 'int32_t', 'void *']);
// TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, fnProgress, ProgressInvokeSetting, Args)
// pObjectName : LPWSTR -> 'str16'
// ObjectType : SE_OBJECT_TYPE -> 'int32_t'
// SecurityInfo : OBJECT_SECURITY_INFORMATION -> 'uint32_t'
// pOwner : PSID optional -> 'void *'
// pGroup : PSID optional -> 'void *'
// pDacl : ACL* optional -> 'void *'
// pSacl : ACL* optional -> 'void *'
// KeepExplicit : BOOL -> 'int32_t'
// fnProgress : FN_PROGRESS optional -> 'void *'
// ProgressInvokeSetting : PROG_INVOKE_SETTING -> 'int32_t'
// Args : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("ADVAPI32.dll", {
  TreeResetNamedSecurityInfoW: { parameters: ["buffer", "i32", "u32", "pointer", "pointer", "pointer", "pointer", "i32", "pointer", "i32", "pointer"], result: "u32" },
});
// lib.symbols.TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, fnProgress, ProgressInvokeSetting, Args)
// pObjectName : LPWSTR -> "buffer"
// ObjectType : SE_OBJECT_TYPE -> "i32"
// SecurityInfo : OBJECT_SECURITY_INFORMATION -> "u32"
// pOwner : PSID optional -> "pointer"
// pGroup : PSID optional -> "pointer"
// pDacl : ACL* optional -> "pointer"
// pSacl : ACL* optional -> "pointer"
// KeepExplicit : BOOL -> "i32"
// fnProgress : FN_PROGRESS optional -> "pointer"
// ProgressInvokeSetting : PROG_INVOKE_SETTING -> "i32"
// Args : void* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t TreeResetNamedSecurityInfoW(
    const uint16_t* pObjectName,
    int32_t ObjectType,
    uint32_t SecurityInfo,
    void* pOwner,
    void* pGroup,
    void* pDacl,
    void* pSacl,
    int32_t KeepExplicit,
    void* fnProgress,
    int32_t ProgressInvokeSetting,
    void* Args);
C, "ADVAPI32.dll");
// $ffi->TreeResetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, pOwner, pGroup, pDacl, pSacl, KeepExplicit, fnProgress, ProgressInvokeSetting, Args);
// pObjectName : LPWSTR
// ObjectType : SE_OBJECT_TYPE
// SecurityInfo : OBJECT_SECURITY_INFORMATION
// pOwner : PSID optional
// pGroup : PSID optional
// pDacl : ACL* optional
// pSacl : ACL* optional
// KeepExplicit : BOOL
// fnProgress : FN_PROGRESS optional
// ProgressInvokeSetting : PROG_INVOKE_SETTING
// Args : void* optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Advapi32 extends StdCallLibrary {
    Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
    int TreeResetNamedSecurityInfoW(
        WString pObjectName,   // LPWSTR
        int ObjectType,   // SE_OBJECT_TYPE
        int SecurityInfo,   // OBJECT_SECURITY_INFORMATION
        Pointer pOwner,   // PSID optional
        Pointer pGroup,   // PSID optional
        Pointer pDacl,   // ACL* optional
        Pointer pSacl,   // ACL* optional
        boolean KeepExplicit,   // BOOL
        Callback fnProgress,   // FN_PROGRESS optional
        int ProgressInvokeSetting,   // PROG_INVOKE_SETTING
        Pointer Args   // void* optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("advapi32")]
lib LibADVAPI32
  fun TreeResetNamedSecurityInfoW = TreeResetNamedSecurityInfoW(
    pObjectName : UInt16*,   # LPWSTR
    ObjectType : Int32,   # SE_OBJECT_TYPE
    SecurityInfo : UInt32,   # OBJECT_SECURITY_INFORMATION
    pOwner : Void*,   # PSID optional
    pGroup : Void*,   # PSID optional
    pDacl : ACL*,   # ACL* optional
    pSacl : ACL*,   # ACL* optional
    KeepExplicit : Int32,   # BOOL
    fnProgress : Void*,   # FN_PROGRESS optional
    ProgressInvokeSetting : Int32,   # PROG_INVOKE_SETTING
    Args : Void*   # void* optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef TreeResetNamedSecurityInfoWNative = Uint32 Function(Pointer<Utf16>, Int32, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Int32, Pointer<Void>, Int32, Pointer<Void>);
typedef TreeResetNamedSecurityInfoWDart = int Function(Pointer<Utf16>, int, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, int, Pointer<Void>, int, Pointer<Void>);
final TreeResetNamedSecurityInfoW = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<TreeResetNamedSecurityInfoWNative, TreeResetNamedSecurityInfoWDart>('TreeResetNamedSecurityInfoW');
// pObjectName : LPWSTR -> Pointer<Utf16>
// ObjectType : SE_OBJECT_TYPE -> Int32
// SecurityInfo : OBJECT_SECURITY_INFORMATION -> Uint32
// pOwner : PSID optional -> Pointer<Void>
// pGroup : PSID optional -> Pointer<Void>
// pDacl : ACL* optional -> Pointer<Void>
// pSacl : ACL* optional -> Pointer<Void>
// KeepExplicit : BOOL -> Int32
// fnProgress : FN_PROGRESS optional -> Pointer<Void>
// ProgressInvokeSetting : PROG_INVOKE_SETTING -> Int32
// Args : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function TreeResetNamedSecurityInfoW(
  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
  KeepExplicit: BOOL;   // BOOL
  fnProgress: Pointer;   // FN_PROGRESS optional
  ProgressInvokeSetting: Integer;   // PROG_INVOKE_SETTING
  Args: Pointer   // void* optional
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'TreeResetNamedSecurityInfoW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "TreeResetNamedSecurityInfoW"
  c_TreeResetNamedSecurityInfoW :: CWString -> Int32 -> Word32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> CInt -> Ptr () -> Int32 -> Ptr () -> IO Word32
-- pObjectName : LPWSTR -> CWString
-- ObjectType : SE_OBJECT_TYPE -> Int32
-- SecurityInfo : OBJECT_SECURITY_INFORMATION -> Word32
-- pOwner : PSID optional -> Ptr ()
-- pGroup : PSID optional -> Ptr ()
-- pDacl : ACL* optional -> Ptr ()
-- pSacl : ACL* optional -> Ptr ()
-- KeepExplicit : BOOL -> CInt
-- fnProgress : FN_PROGRESS optional -> Ptr ()
-- ProgressInvokeSetting : PROG_INVOKE_SETTING -> Int32
-- Args : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let treeresetnamedsecurityinfow =
  foreign "TreeResetNamedSecurityInfoW"
    ((ptr uint16_t) @-> int32_t @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> int32_t @-> (ptr void) @-> int32_t @-> (ptr void) @-> returning uint32_t)
(* pObjectName : LPWSTR -> (ptr uint16_t) *)
(* ObjectType : SE_OBJECT_TYPE -> int32_t *)
(* SecurityInfo : OBJECT_SECURITY_INFORMATION -> uint32_t *)
(* pOwner : PSID optional -> (ptr void) *)
(* pGroup : PSID optional -> (ptr void) *)
(* pDacl : ACL* optional -> (ptr void) *)
(* pSacl : ACL* optional -> (ptr void) *)
(* KeepExplicit : BOOL -> int32_t *)
(* fnProgress : FN_PROGRESS optional -> (ptr void) *)
(* ProgressInvokeSetting : PROG_INVOKE_SETTING -> int32_t *)
(* Args : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("TreeResetNamedSecurityInfoW" tree-reset-named-security-info-w :convention :stdcall) :uint32
  (p-object-name (:string :encoding :utf-16le))   ; LPWSTR
  (object-type :int32)   ; SE_OBJECT_TYPE
  (security-info :uint32)   ; OBJECT_SECURITY_INFORMATION
  (p-owner :pointer)   ; PSID optional
  (p-group :pointer)   ; PSID optional
  (p-dacl :pointer)   ; ACL* optional
  (p-sacl :pointer)   ; ACL* optional
  (keep-explicit :int32)   ; BOOL
  (fn-progress :pointer)   ; FN_PROGRESS optional
  (progress-invoke-setting :int32)   ; PROG_INVOKE_SETTING
  (args :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $TreeResetNamedSecurityInfoW = Win32::API::More->new('ADVAPI32',
    'DWORD TreeResetNamedSecurityInfoW(LPCWSTR pObjectName, int ObjectType, DWORD SecurityInfo, HANDLE pOwner, HANDLE pGroup, LPVOID pDacl, LPVOID pSacl, BOOL KeepExplicit, LPVOID fnProgress, int ProgressInvokeSetting, LPVOID Args)');
# my $ret = $TreeResetNamedSecurityInfoW->Call($pObjectName, $ObjectType, $SecurityInfo, $pOwner, $pGroup, $pDacl, $pSacl, $KeepExplicit, $fnProgress, $ProgressInvokeSetting, $Args);
# pObjectName : LPWSTR -> LPCWSTR
# ObjectType : SE_OBJECT_TYPE -> int
# SecurityInfo : OBJECT_SECURITY_INFORMATION -> DWORD
# pOwner : PSID optional -> HANDLE
# pGroup : PSID optional -> HANDLE
# pDacl : ACL* optional -> LPVOID
# pSacl : ACL* optional -> LPVOID
# KeepExplicit : BOOL -> BOOL
# fnProgress : FN_PROGRESS optional -> LPVOID
# ProgressInvokeSetting : PROG_INVOKE_SETTING -> int
# Args : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型