Win32 API 日本語リファレンス
ホームNetworkManagement.NetManagement › NetAuditWrite

NetAuditWrite

関数
サーバーの監査ログにエントリを書き込む。
DLLNETAPI32.dll呼出規約winapi

シグネチャ

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

DWORD NetAuditWrite(
    DWORD type,
    BYTE* buf,
    DWORD numbytes,
    LPCWSTR service,
    BYTE* reserved
);

パラメーター

名前方向
typeDWORDin
bufBYTE*inout
numbytesDWORDin
serviceLPCWSTRin
reservedBYTE*inout

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD NetAuditWrite(
    DWORD type,
    BYTE* buf,
    DWORD numbytes,
    LPCWSTR service,
    BYTE* reserved
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetAuditWrite(
    uint type,   // DWORD
    IntPtr buf,   // BYTE* in/out
    uint numbytes,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string service,   // LPCWSTR
    IntPtr reserved   // BYTE* in/out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetAuditWrite(
    type As UInteger,   ' DWORD
    buf As IntPtr,   ' BYTE* in/out
    numbytes As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> service As String,   ' LPCWSTR
    reserved As IntPtr   ' BYTE* in/out
) As UInteger
End Function
' type : DWORD
' buf : BYTE* in/out
' numbytes : DWORD
' service : LPCWSTR
' reserved : BYTE* in/out
Declare PtrSafe Function NetAuditWrite Lib "netapi32" ( _
    ByVal type As Long, _
    ByVal buf As LongPtr, _
    ByVal numbytes As Long, _
    ByVal service As LongPtr, _
    ByVal reserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetAuditWrite = ctypes.windll.netapi32.NetAuditWrite
NetAuditWrite.restype = wintypes.DWORD
NetAuditWrite.argtypes = [
    wintypes.DWORD,  # type : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # buf : BYTE* in/out
    wintypes.DWORD,  # numbytes : DWORD
    wintypes.LPCWSTR,  # service : LPCWSTR
    ctypes.POINTER(ctypes.c_ubyte),  # reserved : BYTE* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetAuditWrite = Fiddle::Function.new(
  lib['NetAuditWrite'],
  [
    -Fiddle::TYPE_INT,  # type : DWORD
    Fiddle::TYPE_VOIDP,  # buf : BYTE* in/out
    -Fiddle::TYPE_INT,  # numbytes : DWORD
    Fiddle::TYPE_VOIDP,  # service : LPCWSTR
    Fiddle::TYPE_VOIDP,  # reserved : BYTE* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetAuditWrite(
        type: u32,  // DWORD
        buf: *mut u8,  // BYTE* in/out
        numbytes: u32,  // DWORD
        service: *const u16,  // LPCWSTR
        reserved: *mut u8  // BYTE* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetAuditWrite(uint type, IntPtr buf, uint numbytes, [MarshalAs(UnmanagedType.LPWStr)] string service, IntPtr reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetAuditWrite' -Namespace Win32 -PassThru
# $api::NetAuditWrite(type, buf, numbytes, service, reserved)
#uselib "NETAPI32.dll"
#func global NetAuditWrite "NetAuditWrite" sptr, sptr, sptr, sptr, sptr
; NetAuditWrite type, varptr(buf), numbytes, service, varptr(reserved)   ; 戻り値は stat
; type : DWORD -> "sptr"
; buf : BYTE* in/out -> "sptr"
; numbytes : DWORD -> "sptr"
; service : LPCWSTR -> "sptr"
; reserved : BYTE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NETAPI32.dll"
#cfunc global NetAuditWrite "NetAuditWrite" int, var, int, wstr, var
; res = NetAuditWrite(type, buf, numbytes, service, reserved)
; type : DWORD -> "int"
; buf : BYTE* in/out -> "var"
; numbytes : DWORD -> "int"
; service : LPCWSTR -> "wstr"
; reserved : BYTE* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD NetAuditWrite(DWORD type, BYTE* buf, DWORD numbytes, LPCWSTR service, BYTE* reserved)
#uselib "NETAPI32.dll"
#cfunc global NetAuditWrite "NetAuditWrite" int, var, int, wstr, var
; res = NetAuditWrite(type, buf, numbytes, service, reserved)
; type : DWORD -> "int"
; buf : BYTE* in/out -> "var"
; numbytes : DWORD -> "int"
; service : LPCWSTR -> "wstr"
; reserved : BYTE* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetAuditWrite = netapi32.NewProc("NetAuditWrite")
)

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