ホーム › System.ApplicationInstallationAndServicing › SfcIsFileProtected
SfcIsFileProtected
関数指定したファイルがシステムファイル保護の対象かを判定する。
シグネチャ
// sfc.dll
#include <windows.h>
BOOL SfcIsFileProtected(
HANDLE RpcHandle,
LPCWSTR ProtFileName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| RpcHandle | HANDLE | in | このパラメーターは NULL でなければなりません。 |
| ProtFileName | LPCWSTR | in | ファイルの名前。 |
戻り値の型: BOOL
公式ドキュメント
指定したファイルが保護されているかどうかを判定します。
戻り値
ファイルが保護されている場合、戻り値は 0 以外の値になります。
ファイルが保護されていない場合、戻り値は 0 になります。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "sfc" fn SfcIsFileProtected(
RpcHandle: ?*anyopaque, // HANDLE
ProtFileName: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) i32;proc SfcIsFileProtected(
RpcHandle: pointer, # HANDLE
ProtFileName: WideCString # LPCWSTR
): int32 {.importc: "SfcIsFileProtected", stdcall, dynlib: "sfc.dll".}pragma(lib, "sfc");
extern(Windows)
int SfcIsFileProtected(
void* RpcHandle, // HANDLE
const(wchar)* ProtFileName // LPCWSTR
);ccall((:SfcIsFileProtected, "sfc.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring),
RpcHandle, ProtFileName)
# RpcHandle : HANDLE -> Ptr{Cvoid}
# ProtFileName : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SfcIsFileProtected(
void* RpcHandle,
const uint16_t* ProtFileName);
]]
local sfc = ffi.load("sfc")
-- sfc.SfcIsFileProtected(RpcHandle, ProtFileName)
-- RpcHandle : HANDLE
-- ProtFileName : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('sfc.dll');
const SfcIsFileProtected = lib.func('__stdcall', 'SfcIsFileProtected', 'int32_t', ['void *', 'str16']);
// SfcIsFileProtected(RpcHandle, ProtFileName)
// RpcHandle : HANDLE -> 'void *'
// ProtFileName : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("sfc.dll", {
SfcIsFileProtected: { parameters: ["pointer", "buffer"], result: "i32" },
});
// lib.symbols.SfcIsFileProtected(RpcHandle, ProtFileName)
// RpcHandle : HANDLE -> "pointer"
// ProtFileName : LPCWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SfcIsFileProtected(
void* RpcHandle,
const uint16_t* ProtFileName);
C, "sfc.dll");
// $ffi->SfcIsFileProtected(RpcHandle, ProtFileName);
// RpcHandle : HANDLE
// ProtFileName : LPCWSTR
// 構造体/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 SfcIsFileProtected(
Pointer RpcHandle, // HANDLE
WString ProtFileName // LPCWSTR
);
}@[Link("sfc")]
lib Libsfc
fun SfcIsFileProtected = SfcIsFileProtected(
RpcHandle : Void*, # HANDLE
ProtFileName : UInt16* # LPCWSTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SfcIsFileProtectedNative = Int32 Function(Pointer<Void>, Pointer<Utf16>);
typedef SfcIsFileProtectedDart = int Function(Pointer<Void>, Pointer<Utf16>);
final SfcIsFileProtected = DynamicLibrary.open('sfc.dll')
.lookupFunction<SfcIsFileProtectedNative, SfcIsFileProtectedDart>('SfcIsFileProtected');
// RpcHandle : HANDLE -> Pointer<Void>
// ProtFileName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SfcIsFileProtected(
RpcHandle: THandle; // HANDLE
ProtFileName: PWideChar // LPCWSTR
): BOOL; stdcall;
external 'sfc.dll' name 'SfcIsFileProtected';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SfcIsFileProtected"
c_SfcIsFileProtected :: Ptr () -> CWString -> IO CInt
-- RpcHandle : HANDLE -> Ptr ()
-- ProtFileName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sfcisfileprotected =
foreign "SfcIsFileProtected"
((ptr void) @-> (ptr uint16_t) @-> returning int32_t)
(* RpcHandle : HANDLE -> (ptr void) *)
(* ProtFileName : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library sfc (t "sfc.dll"))
(cffi:use-foreign-library sfc)
(cffi:defcfun ("SfcIsFileProtected" sfc-is-file-protected :convention :stdcall) :int32
(rpc-handle :pointer) ; HANDLE
(prot-file-name (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SfcIsFileProtected = Win32::API::More->new('sfc',
'BOOL SfcIsFileProtected(HANDLE RpcHandle, LPCWSTR ProtFileName)');
# my $ret = $SfcIsFileProtected->Call($RpcHandle, $ProtFileName);
# RpcHandle : HANDLE -> HANDLE
# ProtFileName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f SfcIsKeyProtected — 指定したレジストリキーが保護対象かを判定する。