ホーム › System.ApplicationInstallationAndServicing › SfcIsKeyProtected
SfcIsKeyProtected
関数指定したレジストリキーが保護対象かを判定する。
シグネチャ
// sfc.dll
#include <windows.h>
BOOL SfcIsKeyProtected(
HKEY KeyHandle,
LPCWSTR SubKeyName,
DWORD KeySam
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| KeyHandle | HKEY | in | ルートレジストリキーへのハンドル。これは次の定義済みキーのいずれかへのハンドルでなければなりません。 | ||||||||
| SubKeyName | LPCWSTR | in | サブキーの名前を含むnull終端文字列値。このキーは、hKey パラメーターで識別されるキーのサブキーでなければなりません。キー名の詳細については、Structure of the Registry を参照してください。 このパラメーターが NULL の場合、関数はルートレジストリキーが保護されているかどうかのみを確認します。 | ||||||||
| KeySam | DWORD | in | 64 ビット版 Windows 上で動作するアプリケーションが使用すべき代替レジストリビューを指定する定数。このフラグは x86 プラットフォームでは無視されます。詳細については、Accessing an Alternate Registry View を参照してください。
|
戻り値の型: BOOL
公式ドキュメント
指定したレジストリキーが保護されているかどうかを判定します。
戻り値
キーが保護されている場合、戻り値は 0 以外の値です。
キーが保護されていない場合、戻り値は 0 です。
解説(Remarks)
パスが存在し、かつ WRP によって保護されている場合、そのキーは WRP によって保護されています。SfcIsKeyProtected 関数は、サブキーが WRP によって保護された親キーを持つ場合、そのサブキーが WRP によって保護されていることを示します。
たとえば、次のレジストリキーがシステム上に存在し、WRP によって保護されているとします。
HKEY_LOCAL_MACHINE
SOFTWARE
Classes
Microsoft
<WinFeature>
このとき SfcIsKeyProtected 関数は、次のサブキーに対して 0 以外の値を返します。関数がそのキーを WRP 保護対象と判定するために、新しいサブキーが実際に存在している必要はありません。
HKEY_LOCAL_MACHINE
SOFTWARE
Classes
Microsoft
<WinFeature>
<new subkey>出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// sfc.dll
#include <windows.h>
BOOL SfcIsKeyProtected(
HKEY KeyHandle,
LPCWSTR SubKeyName,
DWORD KeySam
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("sfc.dll", ExactSpelling = true)]
static extern bool SfcIsKeyProtected(
IntPtr KeyHandle, // HKEY
[MarshalAs(UnmanagedType.LPWStr)] string SubKeyName, // LPCWSTR
uint KeySam // DWORD
);<DllImport("sfc.dll", ExactSpelling:=True)>
Public Shared Function SfcIsKeyProtected(
KeyHandle As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPWStr)> SubKeyName As String, ' LPCWSTR
KeySam As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' KeyHandle : HKEY
' SubKeyName : LPCWSTR
' KeySam : DWORD
Declare PtrSafe Function SfcIsKeyProtected Lib "sfc" ( _
ByVal KeyHandle As LongPtr, _
ByVal SubKeyName As LongPtr, _
ByVal KeySam As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SfcIsKeyProtected = ctypes.windll.sfc.SfcIsKeyProtected
SfcIsKeyProtected.restype = wintypes.BOOL
SfcIsKeyProtected.argtypes = [
wintypes.HANDLE, # KeyHandle : HKEY
wintypes.LPCWSTR, # SubKeyName : LPCWSTR
wintypes.DWORD, # KeySam : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('sfc.dll')
SfcIsKeyProtected = Fiddle::Function.new(
lib['SfcIsKeyProtected'],
[
Fiddle::TYPE_VOIDP, # KeyHandle : HKEY
Fiddle::TYPE_VOIDP, # SubKeyName : LPCWSTR
-Fiddle::TYPE_INT, # KeySam : DWORD
],
Fiddle::TYPE_INT)#[link(name = "sfc")]
extern "system" {
fn SfcIsKeyProtected(
KeyHandle: *mut core::ffi::c_void, // HKEY
SubKeyName: *const u16, // LPCWSTR
KeySam: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("sfc.dll")]
public static extern bool SfcIsKeyProtected(IntPtr KeyHandle, [MarshalAs(UnmanagedType.LPWStr)] string SubKeyName, uint KeySam);
"@
$api = Add-Type -MemberDefinition $sig -Name 'sfc_SfcIsKeyProtected' -Namespace Win32 -PassThru
# $api::SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam)#uselib "sfc.dll"
#func global SfcIsKeyProtected "SfcIsKeyProtected" sptr, sptr, sptr
; SfcIsKeyProtected KeyHandle, SubKeyName, KeySam ; 戻り値は stat
; KeyHandle : HKEY -> "sptr"
; SubKeyName : LPCWSTR -> "sptr"
; KeySam : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "sfc.dll"
#cfunc global SfcIsKeyProtected "SfcIsKeyProtected" sptr, wstr, int
; res = SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam)
; KeyHandle : HKEY -> "sptr"
; SubKeyName : LPCWSTR -> "wstr"
; KeySam : DWORD -> "int"; BOOL SfcIsKeyProtected(HKEY KeyHandle, LPCWSTR SubKeyName, DWORD KeySam)
#uselib "sfc.dll"
#cfunc global SfcIsKeyProtected "SfcIsKeyProtected" intptr, wstr, int
; res = SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam)
; KeyHandle : HKEY -> "intptr"
; SubKeyName : LPCWSTR -> "wstr"
; KeySam : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
sfc = windows.NewLazySystemDLL("sfc.dll")
procSfcIsKeyProtected = sfc.NewProc("SfcIsKeyProtected")
)
// KeyHandle (HKEY), SubKeyName (LPCWSTR), KeySam (DWORD)
r1, _, err := procSfcIsKeyProtected.Call(
uintptr(KeyHandle),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SubKeyName))),
uintptr(KeySam),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SfcIsKeyProtected(
KeyHandle: THandle; // HKEY
SubKeyName: PWideChar; // LPCWSTR
KeySam: DWORD // DWORD
): BOOL; stdcall;
external 'sfc.dll' name 'SfcIsKeyProtected';result := DllCall("sfc\SfcIsKeyProtected"
, "Ptr", KeyHandle ; HKEY
, "WStr", SubKeyName ; LPCWSTR
, "UInt", KeySam ; DWORD
, "Int") ; return: BOOL●SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam) = DLL("sfc.dll", "bool SfcIsKeyProtected(void*, char*, dword)")
# 呼び出し: SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam)
# KeyHandle : HKEY -> "void*"
# SubKeyName : LPCWSTR -> "char*"
# KeySam : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "sfc" fn SfcIsKeyProtected(
KeyHandle: ?*anyopaque, // HKEY
SubKeyName: [*c]const u16, // LPCWSTR
KeySam: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc SfcIsKeyProtected(
KeyHandle: pointer, # HKEY
SubKeyName: WideCString, # LPCWSTR
KeySam: uint32 # DWORD
): int32 {.importc: "SfcIsKeyProtected", stdcall, dynlib: "sfc.dll".}pragma(lib, "sfc");
extern(Windows)
int SfcIsKeyProtected(
void* KeyHandle, // HKEY
const(wchar)* SubKeyName, // LPCWSTR
uint KeySam // DWORD
);ccall((:SfcIsKeyProtected, "sfc.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, UInt32),
KeyHandle, SubKeyName, KeySam)
# KeyHandle : HKEY -> Ptr{Cvoid}
# SubKeyName : LPCWSTR -> Cwstring
# KeySam : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SfcIsKeyProtected(
void* KeyHandle,
const uint16_t* SubKeyName,
uint32_t KeySam);
]]
local sfc = ffi.load("sfc")
-- sfc.SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam)
-- KeyHandle : HKEY
-- SubKeyName : LPCWSTR
-- KeySam : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('sfc.dll');
const SfcIsKeyProtected = lib.func('__stdcall', 'SfcIsKeyProtected', 'int32_t', ['void *', 'str16', 'uint32_t']);
// SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam)
// KeyHandle : HKEY -> 'void *'
// SubKeyName : LPCWSTR -> 'str16'
// KeySam : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("sfc.dll", {
SfcIsKeyProtected: { parameters: ["pointer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam)
// KeyHandle : HKEY -> "pointer"
// SubKeyName : LPCWSTR -> "buffer"
// KeySam : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SfcIsKeyProtected(
void* KeyHandle,
const uint16_t* SubKeyName,
uint32_t KeySam);
C, "sfc.dll");
// $ffi->SfcIsKeyProtected(KeyHandle, SubKeyName, KeySam);
// KeyHandle : HKEY
// SubKeyName : LPCWSTR
// KeySam : DWORD
// 構造体/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 Sfc extends StdCallLibrary {
Sfc INSTANCE = Native.load("sfc", Sfc.class);
boolean SfcIsKeyProtected(
Pointer KeyHandle, // HKEY
WString SubKeyName, // LPCWSTR
int KeySam // DWORD
);
}@[Link("sfc")]
lib Libsfc
fun SfcIsKeyProtected = SfcIsKeyProtected(
KeyHandle : Void*, # HKEY
SubKeyName : UInt16*, # LPCWSTR
KeySam : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SfcIsKeyProtectedNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32);
typedef SfcIsKeyProtectedDart = int Function(Pointer<Void>, Pointer<Utf16>, int);
final SfcIsKeyProtected = DynamicLibrary.open('sfc.dll')
.lookupFunction<SfcIsKeyProtectedNative, SfcIsKeyProtectedDart>('SfcIsKeyProtected');
// KeyHandle : HKEY -> Pointer<Void>
// SubKeyName : LPCWSTR -> Pointer<Utf16>
// KeySam : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SfcIsKeyProtected(
KeyHandle: THandle; // HKEY
SubKeyName: PWideChar; // LPCWSTR
KeySam: DWORD // DWORD
): BOOL; stdcall;
external 'sfc.dll' name 'SfcIsKeyProtected';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SfcIsKeyProtected"
c_SfcIsKeyProtected :: Ptr () -> CWString -> Word32 -> IO CInt
-- KeyHandle : HKEY -> Ptr ()
-- SubKeyName : LPCWSTR -> CWString
-- KeySam : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sfciskeyprotected =
foreign "SfcIsKeyProtected"
((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* KeyHandle : HKEY -> (ptr void) *)
(* SubKeyName : LPCWSTR -> (ptr uint16_t) *)
(* KeySam : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library sfc (t "sfc.dll"))
(cffi:use-foreign-library sfc)
(cffi:defcfun ("SfcIsKeyProtected" sfc-is-key-protected :convention :stdcall) :int32
(key-handle :pointer) ; HKEY
(sub-key-name (:string :encoding :utf-16le)) ; LPCWSTR
(key-sam :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SfcIsKeyProtected = Win32::API::More->new('sfc',
'BOOL SfcIsKeyProtected(HANDLE KeyHandle, LPCWSTR SubKeyName, DWORD KeySam)');
# my $ret = $SfcIsKeyProtected->Call($KeyHandle, $SubKeyName, $KeySam);
# KeyHandle : HKEY -> HANDLE
# SubKeyName : LPCWSTR -> LPCWSTR
# KeySam : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f SfcIsFileProtected — 指定したファイルがシステムファイル保護の対象かを判定する。