SetKernelObjectSecurity
関数指定カーネルオブジェクトのセキュリティ記述子を設定する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL SetKernelObjectSecurity(
HANDLE Handle,
OBJECT_SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR SecurityDescriptor
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Handle | HANDLE | in |
| SecurityInformation | OBJECT_SECURITY_INFORMATION | in |
| SecurityDescriptor | PSECURITY_DESCRIPTOR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
BOOL SetKernelObjectSecurity(
HANDLE Handle,
OBJECT_SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR SecurityDescriptor
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetKernelObjectSecurity(
IntPtr Handle, // HANDLE
uint SecurityInformation, // OBJECT_SECURITY_INFORMATION
IntPtr SecurityDescriptor // PSECURITY_DESCRIPTOR
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetKernelObjectSecurity(
Handle As IntPtr, ' HANDLE
SecurityInformation As UInteger, ' OBJECT_SECURITY_INFORMATION
SecurityDescriptor As IntPtr ' PSECURITY_DESCRIPTOR
) As Boolean
End Function' Handle : HANDLE
' SecurityInformation : OBJECT_SECURITY_INFORMATION
' SecurityDescriptor : PSECURITY_DESCRIPTOR
Declare PtrSafe Function SetKernelObjectSecurity Lib "advapi32" ( _
ByVal Handle As LongPtr, _
ByVal SecurityInformation As Long, _
ByVal SecurityDescriptor As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetKernelObjectSecurity = ctypes.windll.advapi32.SetKernelObjectSecurity
SetKernelObjectSecurity.restype = wintypes.BOOL
SetKernelObjectSecurity.argtypes = [
wintypes.HANDLE, # Handle : HANDLE
wintypes.DWORD, # SecurityInformation : OBJECT_SECURITY_INFORMATION
wintypes.HANDLE, # SecurityDescriptor : PSECURITY_DESCRIPTOR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
SetKernelObjectSecurity = Fiddle::Function.new(
lib['SetKernelObjectSecurity'],
[
Fiddle::TYPE_VOIDP, # Handle : HANDLE
-Fiddle::TYPE_INT, # SecurityInformation : OBJECT_SECURITY_INFORMATION
Fiddle::TYPE_VOIDP, # SecurityDescriptor : PSECURITY_DESCRIPTOR
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn SetKernelObjectSecurity(
Handle: *mut core::ffi::c_void, // HANDLE
SecurityInformation: u32, // OBJECT_SECURITY_INFORMATION
SecurityDescriptor: *mut core::ffi::c_void // PSECURITY_DESCRIPTOR
) -> 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 SetKernelObjectSecurity(IntPtr Handle, uint SecurityInformation, IntPtr SecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetKernelObjectSecurity' -Namespace Win32 -PassThru
# $api::SetKernelObjectSecurity(Handle, SecurityInformation, SecurityDescriptor)#uselib "ADVAPI32.dll"
#func global SetKernelObjectSecurity "SetKernelObjectSecurity" sptr, sptr, sptr
; SetKernelObjectSecurity Handle, SecurityInformation, SecurityDescriptor ; 戻り値は stat
; Handle : HANDLE -> "sptr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "sptr"
; SecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global SetKernelObjectSecurity "SetKernelObjectSecurity" sptr, int, sptr
; res = SetKernelObjectSecurity(Handle, SecurityInformation, SecurityDescriptor)
; Handle : HANDLE -> "sptr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int"
; SecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"; BOOL SetKernelObjectSecurity(HANDLE Handle, OBJECT_SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR SecurityDescriptor)
#uselib "ADVAPI32.dll"
#cfunc global SetKernelObjectSecurity "SetKernelObjectSecurity" intptr, int, intptr
; res = SetKernelObjectSecurity(Handle, SecurityInformation, SecurityDescriptor)
; Handle : HANDLE -> "intptr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int"
; SecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procSetKernelObjectSecurity = advapi32.NewProc("SetKernelObjectSecurity")
)
// Handle (HANDLE), SecurityInformation (OBJECT_SECURITY_INFORMATION), SecurityDescriptor (PSECURITY_DESCRIPTOR)
r1, _, err := procSetKernelObjectSecurity.Call(
uintptr(Handle),
uintptr(SecurityInformation),
uintptr(SecurityDescriptor),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetKernelObjectSecurity(
Handle: THandle; // HANDLE
SecurityInformation: DWORD; // OBJECT_SECURITY_INFORMATION
SecurityDescriptor: THandle // PSECURITY_DESCRIPTOR
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'SetKernelObjectSecurity';result := DllCall("ADVAPI32\SetKernelObjectSecurity"
, "Ptr", Handle ; HANDLE
, "UInt", SecurityInformation ; OBJECT_SECURITY_INFORMATION
, "Ptr", SecurityDescriptor ; PSECURITY_DESCRIPTOR
, "Int") ; return: BOOL●SetKernelObjectSecurity(Handle, SecurityInformation, SecurityDescriptor) = DLL("ADVAPI32.dll", "bool SetKernelObjectSecurity(void*, dword, void*)")
# 呼び出し: SetKernelObjectSecurity(Handle, SecurityInformation, SecurityDescriptor)
# Handle : HANDLE -> "void*"
# SecurityInformation : OBJECT_SECURITY_INFORMATION -> "dword"
# SecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。