Win32 API 日本語リファレンス
ホームSystem.ApplicationInstallationAndServicing › SfcIsFileProtected

SfcIsFileProtected

関数
指定したファイルがシステムファイル保護の対象かを判定する。
DLLsfc.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

BOOL SfcIsFileProtected(
    HANDLE RpcHandle,
    LPCWSTR ProtFileName
);

パラメーター

名前方向
RpcHandleHANDLEin
ProtFileNameLPCWSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SfcIsFileProtected(
    HANDLE RpcHandle,
    LPCWSTR ProtFileName
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("sfc.dll", ExactSpelling = true)]
static extern bool SfcIsFileProtected(
    IntPtr RpcHandle,   // HANDLE
    [MarshalAs(UnmanagedType.LPWStr)] string ProtFileName   // LPCWSTR
);
<DllImport("sfc.dll", ExactSpelling:=True)>
Public Shared Function SfcIsFileProtected(
    RpcHandle As IntPtr,   ' HANDLE
    <MarshalAs(UnmanagedType.LPWStr)> ProtFileName As String   ' LPCWSTR
) As Boolean
End Function
' RpcHandle : HANDLE
' ProtFileName : LPCWSTR
Declare PtrSafe Function SfcIsFileProtected Lib "sfc" ( _
    ByVal RpcHandle As LongPtr, _
    ByVal ProtFileName As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SfcIsFileProtected = ctypes.windll.sfc.SfcIsFileProtected
SfcIsFileProtected.restype = wintypes.BOOL
SfcIsFileProtected.argtypes = [
    wintypes.HANDLE,  # RpcHandle : HANDLE
    wintypes.LPCWSTR,  # ProtFileName : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('sfc.dll')
SfcIsFileProtected = Fiddle::Function.new(
  lib['SfcIsFileProtected'],
  [
    Fiddle::TYPE_VOIDP,  # RpcHandle : HANDLE
    Fiddle::TYPE_VOIDP,  # ProtFileName : LPCWSTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "sfc")]
extern "system" {
    fn SfcIsFileProtected(
        RpcHandle: *mut core::ffi::c_void,  // HANDLE
        ProtFileName: *const u16  // LPCWSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("sfc.dll")]
public static extern bool SfcIsFileProtected(IntPtr RpcHandle, [MarshalAs(UnmanagedType.LPWStr)] string ProtFileName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'sfc_SfcIsFileProtected' -Namespace Win32 -PassThru
# $api::SfcIsFileProtected(RpcHandle, ProtFileName)
#uselib "sfc.dll"
#func global SfcIsFileProtected "SfcIsFileProtected" sptr, sptr
; SfcIsFileProtected RpcHandle, ProtFileName   ; 戻り値は stat
; RpcHandle : HANDLE -> "sptr"
; ProtFileName : LPCWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "sfc.dll"
#cfunc global SfcIsFileProtected "SfcIsFileProtected" sptr, wstr
; res = SfcIsFileProtected(RpcHandle, ProtFileName)
; RpcHandle : HANDLE -> "sptr"
; ProtFileName : LPCWSTR -> "wstr"
; BOOL SfcIsFileProtected(HANDLE RpcHandle, LPCWSTR ProtFileName)
#uselib "sfc.dll"
#cfunc global SfcIsFileProtected "SfcIsFileProtected" intptr, wstr
; res = SfcIsFileProtected(RpcHandle, ProtFileName)
; RpcHandle : HANDLE -> "intptr"
; ProtFileName : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	sfc = windows.NewLazySystemDLL("sfc.dll")
	procSfcIsFileProtected = sfc.NewProc("SfcIsFileProtected")
)

// RpcHandle (HANDLE), ProtFileName (LPCWSTR)
r1, _, err := procSfcIsFileProtected.Call(
	uintptr(RpcHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ProtFileName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SfcIsFileProtected(
  RpcHandle: THandle;   // HANDLE
  ProtFileName: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'sfc.dll' name 'SfcIsFileProtected';
result := DllCall("sfc\SfcIsFileProtected"
    , "Ptr", RpcHandle   ; HANDLE
    , "WStr", ProtFileName   ; LPCWSTR
    , "Int")   ; return: BOOL
●SfcIsFileProtected(RpcHandle, ProtFileName) = DLL("sfc.dll", "bool SfcIsFileProtected(void*, char*)")
# 呼び出し: SfcIsFileProtected(RpcHandle, ProtFileName)
# RpcHandle : HANDLE -> "void*"
# ProtFileName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。