Win32 API 日本語リファレンス
ホームStorage.DistributedFileSystem › NetDfsSetSecurity

NetDfsSetSecurity

関数
指定DFSエントリのセキュリティ記述子を設定する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD NetDfsSetSecurity(
    LPWSTR DfsEntryPath,
    DWORD SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);

パラメーター

名前方向
DfsEntryPathLPWSTRin
SecurityInformationDWORDin
pSecurityDescriptorPSECURITY_DESCRIPTORin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD NetDfsSetSecurity(
    LPWSTR DfsEntryPath,
    DWORD SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetDfsSetSecurity(
    [MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath,   // LPWSTR
    uint SecurityInformation,   // DWORD
    IntPtr pSecurityDescriptor   // PSECURITY_DESCRIPTOR
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetDfsSetSecurity(
    <MarshalAs(UnmanagedType.LPWStr)> DfsEntryPath As String,   ' LPWSTR
    SecurityInformation As UInteger,   ' DWORD
    pSecurityDescriptor As IntPtr   ' PSECURITY_DESCRIPTOR
) As UInteger
End Function
' DfsEntryPath : LPWSTR
' SecurityInformation : DWORD
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
Declare PtrSafe Function NetDfsSetSecurity Lib "netapi32" ( _
    ByVal DfsEntryPath As LongPtr, _
    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

NetDfsSetSecurity = ctypes.windll.netapi32.NetDfsSetSecurity
NetDfsSetSecurity.restype = wintypes.DWORD
NetDfsSetSecurity.argtypes = [
    wintypes.LPCWSTR,  # DfsEntryPath : LPWSTR
    wintypes.DWORD,  # SecurityInformation : DWORD
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetDfsSetSecurity = Fiddle::Function.new(
  lib['NetDfsSetSecurity'],
  [
    Fiddle::TYPE_VOIDP,  # DfsEntryPath : LPWSTR
    -Fiddle::TYPE_INT,  # SecurityInformation : DWORD
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetDfsSetSecurity(
        DfsEntryPath: *mut u16,  // LPWSTR
        SecurityInformation: u32,  // DWORD
        pSecurityDescriptor: *mut core::ffi::c_void  // PSECURITY_DESCRIPTOR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetDfsSetSecurity([MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath, uint SecurityInformation, IntPtr pSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetDfsSetSecurity' -Namespace Win32 -PassThru
# $api::NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
#uselib "NETAPI32.dll"
#func global NetDfsSetSecurity "NetDfsSetSecurity" sptr, sptr, sptr
; NetDfsSetSecurity DfsEntryPath, SecurityInformation, pSecurityDescriptor   ; 戻り値は stat
; DfsEntryPath : LPWSTR -> "sptr"
; SecurityInformation : DWORD -> "sptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "NETAPI32.dll"
#cfunc global NetDfsSetSecurity "NetDfsSetSecurity" wstr, int, sptr
; res = NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
; DfsEntryPath : LPWSTR -> "wstr"
; SecurityInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; DWORD NetDfsSetSecurity(LPWSTR DfsEntryPath, DWORD SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor)
#uselib "NETAPI32.dll"
#cfunc global NetDfsSetSecurity "NetDfsSetSecurity" wstr, int, intptr
; res = NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
; DfsEntryPath : LPWSTR -> "wstr"
; SecurityInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetDfsSetSecurity = netapi32.NewProc("NetDfsSetSecurity")
)

// DfsEntryPath (LPWSTR), SecurityInformation (DWORD), pSecurityDescriptor (PSECURITY_DESCRIPTOR)
r1, _, err := procNetDfsSetSecurity.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DfsEntryPath))),
	uintptr(SecurityInformation),
	uintptr(pSecurityDescriptor),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetDfsSetSecurity(
  DfsEntryPath: PWideChar;   // LPWSTR
  SecurityInformation: DWORD;   // DWORD
  pSecurityDescriptor: THandle   // PSECURITY_DESCRIPTOR
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetDfsSetSecurity';
result := DllCall("NETAPI32\NetDfsSetSecurity"
    , "WStr", DfsEntryPath   ; LPWSTR
    , "UInt", SecurityInformation   ; DWORD
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "UInt")   ; return: DWORD
●NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor) = DLL("NETAPI32.dll", "dword NetDfsSetSecurity(char*, dword, void*)")
# 呼び出し: NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
# DfsEntryPath : LPWSTR -> "char*"
# SecurityInformation : DWORD -> "dword"
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。