ホーム › System.Registry › RegGetKeySecurity
RegGetKeySecurity
関数指定したレジストリキーのセキュリティ記述子を取得する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
WIN32_ERROR RegGetKeySecurity(
HKEY hKey,
OBJECT_SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR pSecurityDescriptor, // optional
DWORD* lpcbSecurityDescriptor
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | HKEY | in |
| SecurityInformation | OBJECT_SECURITY_INFORMATION | in |
| pSecurityDescriptor | PSECURITY_DESCRIPTOR | outoptional |
| lpcbSecurityDescriptor | DWORD* | inout |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
WIN32_ERROR RegGetKeySecurity(
HKEY hKey,
OBJECT_SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR pSecurityDescriptor, // optional
DWORD* lpcbSecurityDescriptor
);[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern uint RegGetKeySecurity(
IntPtr hKey, // HKEY
uint SecurityInformation, // OBJECT_SECURITY_INFORMATION
IntPtr pSecurityDescriptor, // PSECURITY_DESCRIPTOR optional, out
ref uint lpcbSecurityDescriptor // DWORD* in/out
);<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function RegGetKeySecurity(
hKey As IntPtr, ' HKEY
SecurityInformation As UInteger, ' OBJECT_SECURITY_INFORMATION
pSecurityDescriptor As IntPtr, ' PSECURITY_DESCRIPTOR optional, out
ByRef lpcbSecurityDescriptor As UInteger ' DWORD* in/out
) As UInteger
End Function' hKey : HKEY
' SecurityInformation : OBJECT_SECURITY_INFORMATION
' pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
' lpcbSecurityDescriptor : DWORD* in/out
Declare PtrSafe Function RegGetKeySecurity Lib "advapi32" ( _
ByVal hKey As LongPtr, _
ByVal SecurityInformation As Long, _
ByVal pSecurityDescriptor As LongPtr, _
ByRef lpcbSecurityDescriptor As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RegGetKeySecurity = ctypes.windll.advapi32.RegGetKeySecurity
RegGetKeySecurity.restype = wintypes.DWORD
RegGetKeySecurity.argtypes = [
wintypes.HANDLE, # hKey : HKEY
wintypes.DWORD, # SecurityInformation : OBJECT_SECURITY_INFORMATION
wintypes.HANDLE, # pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
ctypes.POINTER(wintypes.DWORD), # lpcbSecurityDescriptor : DWORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
RegGetKeySecurity = Fiddle::Function.new(
lib['RegGetKeySecurity'],
[
Fiddle::TYPE_VOIDP, # hKey : HKEY
-Fiddle::TYPE_INT, # SecurityInformation : OBJECT_SECURITY_INFORMATION
Fiddle::TYPE_VOIDP, # pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
Fiddle::TYPE_VOIDP, # lpcbSecurityDescriptor : DWORD* in/out
],
-Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn RegGetKeySecurity(
hKey: *mut core::ffi::c_void, // HKEY
SecurityInformation: u32, // OBJECT_SECURITY_INFORMATION
pSecurityDescriptor: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR optional, out
lpcbSecurityDescriptor: *mut u32 // DWORD* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern uint RegGetKeySecurity(IntPtr hKey, uint SecurityInformation, IntPtr pSecurityDescriptor, ref uint lpcbSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegGetKeySecurity' -Namespace Win32 -PassThru
# $api::RegGetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor, lpcbSecurityDescriptor)#uselib "ADVAPI32.dll"
#func global RegGetKeySecurity "RegGetKeySecurity" sptr, sptr, sptr, sptr
; RegGetKeySecurity hKey, SecurityInformation, pSecurityDescriptor, varptr(lpcbSecurityDescriptor) ; 戻り値は stat
; hKey : HKEY -> "sptr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "sptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr"
; lpcbSecurityDescriptor : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global RegGetKeySecurity "RegGetKeySecurity" sptr, int, sptr, var ; res = RegGetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor, lpcbSecurityDescriptor) ; hKey : HKEY -> "sptr" ; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int" ; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; lpcbSecurityDescriptor : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global RegGetKeySecurity "RegGetKeySecurity" sptr, int, sptr, sptr ; res = RegGetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor, varptr(lpcbSecurityDescriptor)) ; hKey : HKEY -> "sptr" ; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int" ; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; lpcbSecurityDescriptor : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR RegGetKeySecurity(HKEY hKey, OBJECT_SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD* lpcbSecurityDescriptor) #uselib "ADVAPI32.dll" #cfunc global RegGetKeySecurity "RegGetKeySecurity" intptr, int, intptr, var ; res = RegGetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor, lpcbSecurityDescriptor) ; hKey : HKEY -> "intptr" ; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int" ; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; lpcbSecurityDescriptor : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR RegGetKeySecurity(HKEY hKey, OBJECT_SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD* lpcbSecurityDescriptor) #uselib "ADVAPI32.dll" #cfunc global RegGetKeySecurity "RegGetKeySecurity" intptr, int, intptr, intptr ; res = RegGetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor, varptr(lpcbSecurityDescriptor)) ; hKey : HKEY -> "intptr" ; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int" ; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; lpcbSecurityDescriptor : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procRegGetKeySecurity = advapi32.NewProc("RegGetKeySecurity")
)
// hKey (HKEY), SecurityInformation (OBJECT_SECURITY_INFORMATION), pSecurityDescriptor (PSECURITY_DESCRIPTOR optional, out), lpcbSecurityDescriptor (DWORD* in/out)
r1, _, err := procRegGetKeySecurity.Call(
uintptr(hKey),
uintptr(SecurityInformation),
uintptr(pSecurityDescriptor),
uintptr(lpcbSecurityDescriptor),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction RegGetKeySecurity(
hKey: THandle; // HKEY
SecurityInformation: DWORD; // OBJECT_SECURITY_INFORMATION
pSecurityDescriptor: THandle; // PSECURITY_DESCRIPTOR optional, out
lpcbSecurityDescriptor: Pointer // DWORD* in/out
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'RegGetKeySecurity';result := DllCall("ADVAPI32\RegGetKeySecurity"
, "Ptr", hKey ; HKEY
, "UInt", SecurityInformation ; OBJECT_SECURITY_INFORMATION
, "Ptr", pSecurityDescriptor ; PSECURITY_DESCRIPTOR optional, out
, "Ptr", lpcbSecurityDescriptor ; DWORD* in/out
, "UInt") ; return: WIN32_ERROR●RegGetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor, lpcbSecurityDescriptor) = DLL("ADVAPI32.dll", "dword RegGetKeySecurity(void*, dword, void*, void*)")
# 呼び出し: RegGetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor, lpcbSecurityDescriptor)
# hKey : HKEY -> "void*"
# SecurityInformation : OBJECT_SECURITY_INFORMATION -> "dword"
# pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "void*"
# lpcbSecurityDescriptor : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。