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