ホーム › Security.EnterpriseData › UnprotectFile
UnprotectFile
関数企業IDで保護されたファイルの保護を解除する。
シグネチャ
// efswrt.dll
#include <windows.h>
HRESULT UnprotectFile(
LPCWSTR fileOrFolderPath,
const FILE_UNPROTECT_OPTIONS* options // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| fileOrFolderPath | LPCWSTR | in | 保護を解除する対象のファイルまたはフォルダーのパス。 |
| options | FILE_UNPROTECT_OPTIONS* | inoptional | 解除動作を指定するFILE_UNPROTECT_OPTIONS構造体へのポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// efswrt.dll
#include <windows.h>
HRESULT UnprotectFile(
LPCWSTR fileOrFolderPath,
const FILE_UNPROTECT_OPTIONS* options // optional
);[DllImport("efswrt.dll", ExactSpelling = true)]
static extern int UnprotectFile(
[MarshalAs(UnmanagedType.LPWStr)] string fileOrFolderPath, // LPCWSTR
IntPtr options // FILE_UNPROTECT_OPTIONS* optional
);<DllImport("efswrt.dll", ExactSpelling:=True)>
Public Shared Function UnprotectFile(
<MarshalAs(UnmanagedType.LPWStr)> fileOrFolderPath As String, ' LPCWSTR
options As IntPtr ' FILE_UNPROTECT_OPTIONS* optional
) As Integer
End Function' fileOrFolderPath : LPCWSTR
' options : FILE_UNPROTECT_OPTIONS* optional
Declare PtrSafe Function UnprotectFile Lib "efswrt" ( _
ByVal fileOrFolderPath As LongPtr, _
ByVal options As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
UnprotectFile = ctypes.windll.efswrt.UnprotectFile
UnprotectFile.restype = ctypes.c_int
UnprotectFile.argtypes = [
wintypes.LPCWSTR, # fileOrFolderPath : LPCWSTR
ctypes.c_void_p, # options : FILE_UNPROTECT_OPTIONS* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('efswrt.dll')
UnprotectFile = Fiddle::Function.new(
lib['UnprotectFile'],
[
Fiddle::TYPE_VOIDP, # fileOrFolderPath : LPCWSTR
Fiddle::TYPE_VOIDP, # options : FILE_UNPROTECT_OPTIONS* optional
],
Fiddle::TYPE_INT)#[link(name = "efswrt")]
extern "system" {
fn UnprotectFile(
fileOrFolderPath: *const u16, // LPCWSTR
options: *const FILE_UNPROTECT_OPTIONS // FILE_UNPROTECT_OPTIONS* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("efswrt.dll")]
public static extern int UnprotectFile([MarshalAs(UnmanagedType.LPWStr)] string fileOrFolderPath, IntPtr options);
"@
$api = Add-Type -MemberDefinition $sig -Name 'efswrt_UnprotectFile' -Namespace Win32 -PassThru
# $api::UnprotectFile(fileOrFolderPath, options)#uselib "efswrt.dll"
#func global UnprotectFile "UnprotectFile" sptr, sptr
; UnprotectFile fileOrFolderPath, varptr(options) ; 戻り値は stat
; fileOrFolderPath : LPCWSTR -> "sptr"
; options : FILE_UNPROTECT_OPTIONS* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "efswrt.dll" #cfunc global UnprotectFile "UnprotectFile" wstr, var ; res = UnprotectFile(fileOrFolderPath, options) ; fileOrFolderPath : LPCWSTR -> "wstr" ; options : FILE_UNPROTECT_OPTIONS* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "efswrt.dll" #cfunc global UnprotectFile "UnprotectFile" wstr, sptr ; res = UnprotectFile(fileOrFolderPath, varptr(options)) ; fileOrFolderPath : LPCWSTR -> "wstr" ; options : FILE_UNPROTECT_OPTIONS* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT UnprotectFile(LPCWSTR fileOrFolderPath, FILE_UNPROTECT_OPTIONS* options) #uselib "efswrt.dll" #cfunc global UnprotectFile "UnprotectFile" wstr, var ; res = UnprotectFile(fileOrFolderPath, options) ; fileOrFolderPath : LPCWSTR -> "wstr" ; options : FILE_UNPROTECT_OPTIONS* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT UnprotectFile(LPCWSTR fileOrFolderPath, FILE_UNPROTECT_OPTIONS* options) #uselib "efswrt.dll" #cfunc global UnprotectFile "UnprotectFile" wstr, intptr ; res = UnprotectFile(fileOrFolderPath, varptr(options)) ; fileOrFolderPath : LPCWSTR -> "wstr" ; options : FILE_UNPROTECT_OPTIONS* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
efswrt = windows.NewLazySystemDLL("efswrt.dll")
procUnprotectFile = efswrt.NewProc("UnprotectFile")
)
// fileOrFolderPath (LPCWSTR), options (FILE_UNPROTECT_OPTIONS* optional)
r1, _, err := procUnprotectFile.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(fileOrFolderPath))),
uintptr(options),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction UnprotectFile(
fileOrFolderPath: PWideChar; // LPCWSTR
options: Pointer // FILE_UNPROTECT_OPTIONS* optional
): Integer; stdcall;
external 'efswrt.dll' name 'UnprotectFile';result := DllCall("efswrt\UnprotectFile"
, "WStr", fileOrFolderPath ; LPCWSTR
, "Ptr", options ; FILE_UNPROTECT_OPTIONS* optional
, "Int") ; return: HRESULT●UnprotectFile(fileOrFolderPath, options) = DLL("efswrt.dll", "int UnprotectFile(char*, void*)")
# 呼び出し: UnprotectFile(fileOrFolderPath, options)
# fileOrFolderPath : LPCWSTR -> "char*"
# options : FILE_UNPROTECT_OPTIONS* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "efswrt" fn UnprotectFile(
fileOrFolderPath: [*c]const u16, // LPCWSTR
options: [*c]FILE_UNPROTECT_OPTIONS // FILE_UNPROTECT_OPTIONS* optional
) callconv(std.os.windows.WINAPI) i32;proc UnprotectFile(
fileOrFolderPath: WideCString, # LPCWSTR
options: ptr FILE_UNPROTECT_OPTIONS # FILE_UNPROTECT_OPTIONS* optional
): int32 {.importc: "UnprotectFile", stdcall, dynlib: "efswrt.dll".}pragma(lib, "efswrt");
extern(Windows)
int UnprotectFile(
const(wchar)* fileOrFolderPath, // LPCWSTR
FILE_UNPROTECT_OPTIONS* options // FILE_UNPROTECT_OPTIONS* optional
);ccall((:UnprotectFile, "efswrt.dll"), stdcall, Int32,
(Cwstring, Ptr{FILE_UNPROTECT_OPTIONS}),
fileOrFolderPath, options)
# fileOrFolderPath : LPCWSTR -> Cwstring
# options : FILE_UNPROTECT_OPTIONS* optional -> Ptr{FILE_UNPROTECT_OPTIONS}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t UnprotectFile(
const uint16_t* fileOrFolderPath,
void* options);
]]
local efswrt = ffi.load("efswrt")
-- efswrt.UnprotectFile(fileOrFolderPath, options)
-- fileOrFolderPath : LPCWSTR
-- options : FILE_UNPROTECT_OPTIONS* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('efswrt.dll');
const UnprotectFile = lib.func('__stdcall', 'UnprotectFile', 'int32_t', ['str16', 'void *']);
// UnprotectFile(fileOrFolderPath, options)
// fileOrFolderPath : LPCWSTR -> 'str16'
// options : FILE_UNPROTECT_OPTIONS* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("efswrt.dll", {
UnprotectFile: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.UnprotectFile(fileOrFolderPath, options)
// fileOrFolderPath : LPCWSTR -> "buffer"
// options : FILE_UNPROTECT_OPTIONS* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t UnprotectFile(
const uint16_t* fileOrFolderPath,
void* options);
C, "efswrt.dll");
// $ffi->UnprotectFile(fileOrFolderPath, options);
// fileOrFolderPath : LPCWSTR
// options : FILE_UNPROTECT_OPTIONS* optional
// 構造体/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 Efswrt extends StdCallLibrary {
Efswrt INSTANCE = Native.load("efswrt", Efswrt.class);
int UnprotectFile(
WString fileOrFolderPath, // LPCWSTR
Pointer options // FILE_UNPROTECT_OPTIONS* optional
);
}@[Link("efswrt")]
lib Libefswrt
fun UnprotectFile = UnprotectFile(
fileOrFolderPath : UInt16*, # LPCWSTR
options : FILE_UNPROTECT_OPTIONS* # FILE_UNPROTECT_OPTIONS* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef UnprotectFileNative = Int32 Function(Pointer<Utf16>, Pointer<Void>);
typedef UnprotectFileDart = int Function(Pointer<Utf16>, Pointer<Void>);
final UnprotectFile = DynamicLibrary.open('efswrt.dll')
.lookupFunction<UnprotectFileNative, UnprotectFileDart>('UnprotectFile');
// fileOrFolderPath : LPCWSTR -> Pointer<Utf16>
// options : FILE_UNPROTECT_OPTIONS* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function UnprotectFile(
fileOrFolderPath: PWideChar; // LPCWSTR
options: Pointer // FILE_UNPROTECT_OPTIONS* optional
): Integer; stdcall;
external 'efswrt.dll' name 'UnprotectFile';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "UnprotectFile"
c_UnprotectFile :: CWString -> Ptr () -> IO Int32
-- fileOrFolderPath : LPCWSTR -> CWString
-- options : FILE_UNPROTECT_OPTIONS* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let unprotectfile =
foreign "UnprotectFile"
((ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* fileOrFolderPath : LPCWSTR -> (ptr uint16_t) *)
(* options : FILE_UNPROTECT_OPTIONS* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library efswrt (t "efswrt.dll"))
(cffi:use-foreign-library efswrt)
(cffi:defcfun ("UnprotectFile" unprotect-file :convention :stdcall) :int32
(file-or-folder-path (:string :encoding :utf-16le)) ; LPCWSTR
(options :pointer)) ; FILE_UNPROTECT_OPTIONS* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $UnprotectFile = Win32::API::More->new('efswrt',
'int UnprotectFile(LPCWSTR fileOrFolderPath, LPVOID options)');
# my $ret = $UnprotectFile->Call($fileOrFolderPath, $options);
# fileOrFolderPath : LPCWSTR -> LPCWSTR
# options : FILE_UNPROTECT_OPTIONS* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。