SetFileSecurityA
関数指定ファイルのセキュリティ情報を設定する(ANSI版)。
シグネチャ
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL SetFileSecurityA(
LPCSTR lpFileName,
OBJECT_SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR pSecurityDescriptor
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpFileName | LPCSTR | in |
| SecurityInformation | OBJECT_SECURITY_INFORMATION | in |
| pSecurityDescriptor | PSECURITY_DESCRIPTOR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL SetFileSecurityA(
LPCSTR lpFileName,
OBJECT_SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR pSecurityDescriptor
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetFileSecurityA(
[MarshalAs(UnmanagedType.LPStr)] string lpFileName, // LPCSTR
uint SecurityInformation, // OBJECT_SECURITY_INFORMATION
IntPtr pSecurityDescriptor // PSECURITY_DESCRIPTOR
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetFileSecurityA(
<MarshalAs(UnmanagedType.LPStr)> lpFileName As String, ' LPCSTR
SecurityInformation As UInteger, ' OBJECT_SECURITY_INFORMATION
pSecurityDescriptor As IntPtr ' PSECURITY_DESCRIPTOR
) As Boolean
End Function' lpFileName : LPCSTR
' SecurityInformation : OBJECT_SECURITY_INFORMATION
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
Declare PtrSafe Function SetFileSecurityA Lib "advapi32" ( _
ByVal lpFileName As String, _
ByVal SecurityInformation As Long, _
ByVal pSecurityDescriptor As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetFileSecurityA = ctypes.windll.advapi32.SetFileSecurityA
SetFileSecurityA.restype = wintypes.BOOL
SetFileSecurityA.argtypes = [
wintypes.LPCSTR, # lpFileName : LPCSTR
wintypes.DWORD, # SecurityInformation : OBJECT_SECURITY_INFORMATION
wintypes.HANDLE, # pSecurityDescriptor : PSECURITY_DESCRIPTOR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
SetFileSecurityA = Fiddle::Function.new(
lib['SetFileSecurityA'],
[
Fiddle::TYPE_VOIDP, # lpFileName : LPCSTR
-Fiddle::TYPE_INT, # SecurityInformation : OBJECT_SECURITY_INFORMATION
Fiddle::TYPE_VOIDP, # pSecurityDescriptor : PSECURITY_DESCRIPTOR
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn SetFileSecurityA(
lpFileName: *const u8, // LPCSTR
SecurityInformation: u32, // OBJECT_SECURITY_INFORMATION
pSecurityDescriptor: *mut core::ffi::c_void // PSECURITY_DESCRIPTOR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetFileSecurityA([MarshalAs(UnmanagedType.LPStr)] string lpFileName, uint SecurityInformation, IntPtr pSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetFileSecurityA' -Namespace Win32 -PassThru
# $api::SetFileSecurityA(lpFileName, SecurityInformation, pSecurityDescriptor)#uselib "ADVAPI32.dll"
#func global SetFileSecurityA "SetFileSecurityA" sptr, sptr, sptr
; SetFileSecurityA lpFileName, SecurityInformation, pSecurityDescriptor ; 戻り値は stat
; lpFileName : LPCSTR -> "sptr"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "sptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global SetFileSecurityA "SetFileSecurityA" str, int, sptr
; res = SetFileSecurityA(lpFileName, SecurityInformation, pSecurityDescriptor)
; lpFileName : LPCSTR -> "str"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"; BOOL SetFileSecurityA(LPCSTR lpFileName, OBJECT_SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor)
#uselib "ADVAPI32.dll"
#cfunc global SetFileSecurityA "SetFileSecurityA" str, int, intptr
; res = SetFileSecurityA(lpFileName, SecurityInformation, pSecurityDescriptor)
; lpFileName : LPCSTR -> "str"
; SecurityInformation : OBJECT_SECURITY_INFORMATION -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procSetFileSecurityA = advapi32.NewProc("SetFileSecurityA")
)
// lpFileName (LPCSTR), SecurityInformation (OBJECT_SECURITY_INFORMATION), pSecurityDescriptor (PSECURITY_DESCRIPTOR)
r1, _, err := procSetFileSecurityA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFileName))),
uintptr(SecurityInformation),
uintptr(pSecurityDescriptor),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetFileSecurityA(
lpFileName: PAnsiChar; // LPCSTR
SecurityInformation: DWORD; // OBJECT_SECURITY_INFORMATION
pSecurityDescriptor: THandle // PSECURITY_DESCRIPTOR
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'SetFileSecurityA';result := DllCall("ADVAPI32\SetFileSecurityA"
, "AStr", lpFileName ; LPCSTR
, "UInt", SecurityInformation ; OBJECT_SECURITY_INFORMATION
, "Ptr", pSecurityDescriptor ; PSECURITY_DESCRIPTOR
, "Int") ; return: BOOL●SetFileSecurityA(lpFileName, SecurityInformation, pSecurityDescriptor) = DLL("ADVAPI32.dll", "bool SetFileSecurityA(char*, dword, void*)")
# 呼び出し: SetFileSecurityA(lpFileName, SecurityInformation, pSecurityDescriptor)
# lpFileName : LPCSTR -> "char*"
# SecurityInformation : OBJECT_SECURITY_INFORMATION -> "dword"
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。