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