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

SetSecurityDescriptorOwner

関数
セキュリティ記述子の所有者SIDを設定する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetSecurityDescriptorOwner(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    PSID pOwner,   // optional
    BOOL bOwnerDefaulted
);

パラメーター

名前方向
pSecurityDescriptorPSECURITY_DESCRIPTORinout
pOwnerPSIDinoptional
bOwnerDefaultedBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

SetSecurityDescriptorOwner = ctypes.windll.advapi32.SetSecurityDescriptorOwner
SetSecurityDescriptorOwner.restype = wintypes.BOOL
SetSecurityDescriptorOwner.argtypes = [
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
    wintypes.HANDLE,  # pOwner : PSID optional
    wintypes.BOOL,  # bOwnerDefaulted : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
SetSecurityDescriptorOwner = Fiddle::Function.new(
  lib['SetSecurityDescriptorOwner'],
  [
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
    Fiddle::TYPE_VOIDP,  # pOwner : PSID optional
    Fiddle::TYPE_INT,  # bOwnerDefaulted : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SetSecurityDescriptorOwner(
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR in/out
        pOwner: *mut core::ffi::c_void,  // PSID optional
        bOwnerDefaulted: i32  // BOOL
    ) -> 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 SetSecurityDescriptorOwner(IntPtr pSecurityDescriptor, IntPtr pOwner, bool bOwnerDefaulted);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetSecurityDescriptorOwner' -Namespace Win32 -PassThru
# $api::SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
#uselib "ADVAPI32.dll"
#func global SetSecurityDescriptorOwner "SetSecurityDescriptorOwner" sptr, sptr, sptr
; SetSecurityDescriptorOwner pSecurityDescriptor, pOwner, bOwnerDefaulted   ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr"
; pOwner : PSID optional -> "sptr"
; bOwnerDefaulted : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorOwner "SetSecurityDescriptorOwner" sptr, sptr, int
; res = SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr"
; pOwner : PSID optional -> "sptr"
; bOwnerDefaulted : BOOL -> "int"
; BOOL SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pOwner, BOOL bOwnerDefaulted)
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorOwner "SetSecurityDescriptorOwner" intptr, intptr, int
; res = SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "intptr"
; pOwner : PSID optional -> "intptr"
; bOwnerDefaulted : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSetSecurityDescriptorOwner = advapi32.NewProc("SetSecurityDescriptorOwner")
)

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