Win32 API 日本語リファレンス
ホームNetworking.Clustering › ClusterRegSetKeySecurity

ClusterRegSetKeySecurity

関数
クラスタレジストリキーにセキュリティ記述子を設定する。
DLLCLUSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

INT ClusterRegSetKeySecurity(
    HKEY hKey,
    DWORD SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);

パラメーター

名前方向説明
hKeyHKEYinセキュリティ情報を設定する対象の開いているクラスターレジストリキー。
SecurityInformationDWORDin設定するセキュリティ情報の種別を示すフラグ。
pSecurityDescriptorPSECURITY_DESCRIPTORin適用するセキュリティ記述子へのポインタ。

戻り値の型: INT

各言語での呼び出し定義

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

INT ClusterRegSetKeySecurity(
    HKEY hKey,
    DWORD SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);
[DllImport("CLUSAPI.dll", ExactSpelling = true)]
static extern int ClusterRegSetKeySecurity(
    IntPtr hKey,   // HKEY
    uint SecurityInformation,   // DWORD
    IntPtr pSecurityDescriptor   // PSECURITY_DESCRIPTOR
);
<DllImport("CLUSAPI.dll", ExactSpelling:=True)>
Public Shared Function ClusterRegSetKeySecurity(
    hKey As IntPtr,   ' HKEY
    SecurityInformation As UInteger,   ' DWORD
    pSecurityDescriptor As IntPtr   ' PSECURITY_DESCRIPTOR
) As Integer
End Function
' hKey : HKEY
' SecurityInformation : DWORD
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
Declare PtrSafe Function ClusterRegSetKeySecurity Lib "clusapi" ( _
    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

ClusterRegSetKeySecurity = ctypes.windll.clusapi.ClusterRegSetKeySecurity
ClusterRegSetKeySecurity.restype = ctypes.c_int
ClusterRegSetKeySecurity.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.DWORD,  # SecurityInformation : DWORD
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CLUSAPI.dll')
ClusterRegSetKeySecurity = Fiddle::Function.new(
  lib['ClusterRegSetKeySecurity'],
  [
    Fiddle::TYPE_VOIDP,  # hKey : HKEY
    -Fiddle::TYPE_INT,  # SecurityInformation : DWORD
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
  ],
  Fiddle::TYPE_INT)
#[link(name = "clusapi")]
extern "system" {
    fn ClusterRegSetKeySecurity(
        hKey: *mut core::ffi::c_void,  // HKEY
        SecurityInformation: u32,  // DWORD
        pSecurityDescriptor: *mut core::ffi::c_void  // PSECURITY_DESCRIPTOR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CLUSAPI.dll")]
public static extern int ClusterRegSetKeySecurity(IntPtr hKey, uint SecurityInformation, IntPtr pSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CLUSAPI_ClusterRegSetKeySecurity' -Namespace Win32 -PassThru
# $api::ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor)
#uselib "CLUSAPI.dll"
#func global ClusterRegSetKeySecurity "ClusterRegSetKeySecurity" sptr, sptr, sptr
; ClusterRegSetKeySecurity hKey, SecurityInformation, pSecurityDescriptor   ; 戻り値は stat
; hKey : HKEY -> "sptr"
; SecurityInformation : DWORD -> "sptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CLUSAPI.dll"
#cfunc global ClusterRegSetKeySecurity "ClusterRegSetKeySecurity" sptr, int, sptr
; res = ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor)
; hKey : HKEY -> "sptr"
; SecurityInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; INT ClusterRegSetKeySecurity(HKEY hKey, DWORD SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor)
#uselib "CLUSAPI.dll"
#cfunc global ClusterRegSetKeySecurity "ClusterRegSetKeySecurity" intptr, int, intptr
; res = ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor)
; hKey : HKEY -> "intptr"
; SecurityInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procClusterRegSetKeySecurity = clusapi.NewProc("ClusterRegSetKeySecurity")
)

// hKey (HKEY), SecurityInformation (DWORD), pSecurityDescriptor (PSECURITY_DESCRIPTOR)
r1, _, err := procClusterRegSetKeySecurity.Call(
	uintptr(hKey),
	uintptr(SecurityInformation),
	uintptr(pSecurityDescriptor),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function ClusterRegSetKeySecurity(
  hKey: THandle;   // HKEY
  SecurityInformation: DWORD;   // DWORD
  pSecurityDescriptor: THandle   // PSECURITY_DESCRIPTOR
): Integer; stdcall;
  external 'CLUSAPI.dll' name 'ClusterRegSetKeySecurity';
result := DllCall("CLUSAPI\ClusterRegSetKeySecurity"
    , "Ptr", hKey   ; HKEY
    , "UInt", SecurityInformation   ; DWORD
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "Int")   ; return: INT
●ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor) = DLL("CLUSAPI.dll", "int ClusterRegSetKeySecurity(void*, dword, void*)")
# 呼び出し: ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor)
# hKey : HKEY -> "void*"
# SecurityInformation : DWORD -> "dword"
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "clusapi" fn ClusterRegSetKeySecurity(
    hKey: ?*anyopaque, // HKEY
    SecurityInformation: u32, // DWORD
    pSecurityDescriptor: ?*anyopaque // PSECURITY_DESCRIPTOR
) callconv(std.os.windows.WINAPI) i32;
proc ClusterRegSetKeySecurity(
    hKey: pointer,  # HKEY
    SecurityInformation: uint32,  # DWORD
    pSecurityDescriptor: pointer  # PSECURITY_DESCRIPTOR
): int32 {.importc: "ClusterRegSetKeySecurity", stdcall, dynlib: "CLUSAPI.dll".}
pragma(lib, "clusapi");
extern(Windows)
int ClusterRegSetKeySecurity(
    void* hKey,   // HKEY
    uint SecurityInformation,   // DWORD
    void* pSecurityDescriptor   // PSECURITY_DESCRIPTOR
);
ccall((:ClusterRegSetKeySecurity, "CLUSAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Ptr{Cvoid}),
      hKey, SecurityInformation, pSecurityDescriptor)
# hKey : HKEY -> Ptr{Cvoid}
# SecurityInformation : DWORD -> UInt32
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ClusterRegSetKeySecurity(
    void* hKey,
    uint32_t SecurityInformation,
    void* pSecurityDescriptor);
]]
local clusapi = ffi.load("clusapi")
-- clusapi.ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor)
-- hKey : HKEY
-- SecurityInformation : DWORD
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CLUSAPI.dll');
const ClusterRegSetKeySecurity = lib.func('__stdcall', 'ClusterRegSetKeySecurity', 'int32_t', ['void *', 'uint32_t', 'void *']);
// ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor)
// hKey : HKEY -> 'void *'
// SecurityInformation : DWORD -> 'uint32_t'
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CLUSAPI.dll", {
  ClusterRegSetKeySecurity: { parameters: ["pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor)
// hKey : HKEY -> "pointer"
// SecurityInformation : DWORD -> "u32"
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ClusterRegSetKeySecurity(
    void* hKey,
    uint32_t SecurityInformation,
    void* pSecurityDescriptor);
C, "CLUSAPI.dll");
// $ffi->ClusterRegSetKeySecurity(hKey, SecurityInformation, pSecurityDescriptor);
// hKey : HKEY
// SecurityInformation : DWORD
// pSecurityDescriptor : PSECURITY_DESCRIPTOR
// 構造体/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 Clusapi extends StdCallLibrary {
    Clusapi INSTANCE = Native.load("clusapi", Clusapi.class);
    int ClusterRegSetKeySecurity(
        Pointer hKey,   // HKEY
        int SecurityInformation,   // DWORD
        Pointer pSecurityDescriptor   // PSECURITY_DESCRIPTOR
    );
}
@[Link("clusapi")]
lib LibCLUSAPI
  fun ClusterRegSetKeySecurity = ClusterRegSetKeySecurity(
    hKey : Void*,   # HKEY
    SecurityInformation : UInt32,   # DWORD
    pSecurityDescriptor : Void*   # PSECURITY_DESCRIPTOR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ClusterRegSetKeySecurityNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>);
typedef ClusterRegSetKeySecurityDart = int Function(Pointer<Void>, int, Pointer<Void>);
final ClusterRegSetKeySecurity = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<ClusterRegSetKeySecurityNative, ClusterRegSetKeySecurityDart>('ClusterRegSetKeySecurity');
// hKey : HKEY -> Pointer<Void>
// SecurityInformation : DWORD -> Uint32
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ClusterRegSetKeySecurity(
  hKey: THandle;   // HKEY
  SecurityInformation: DWORD;   // DWORD
  pSecurityDescriptor: THandle   // PSECURITY_DESCRIPTOR
): Integer; stdcall;
  external 'CLUSAPI.dll' name 'ClusterRegSetKeySecurity';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ClusterRegSetKeySecurity"
  c_ClusterRegSetKeySecurity :: Ptr () -> Word32 -> Ptr () -> IO Int32
-- hKey : HKEY -> Ptr ()
-- SecurityInformation : DWORD -> Word32
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let clusterregsetkeysecurity =
  foreign "ClusterRegSetKeySecurity"
    ((ptr void) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hKey : HKEY -> (ptr void) *)
(* SecurityInformation : DWORD -> uint32_t *)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library clusapi (t "CLUSAPI.dll"))
(cffi:use-foreign-library clusapi)

(cffi:defcfun ("ClusterRegSetKeySecurity" cluster-reg-set-key-security :convention :stdcall) :int32
  (h-key :pointer)   ; HKEY
  (security-information :uint32)   ; DWORD
  (p-security-descriptor :pointer))   ; PSECURITY_DESCRIPTOR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ClusterRegSetKeySecurity = Win32::API::More->new('CLUSAPI',
    'int ClusterRegSetKeySecurity(HANDLE hKey, DWORD SecurityInformation, HANDLE pSecurityDescriptor)');
# my $ret = $ClusterRegSetKeySecurity->Call($hKey, $SecurityInformation, $pSecurityDescriptor);
# hKey : HKEY -> HANDLE
# SecurityInformation : DWORD -> DWORD
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API