Win32 API 日本語リファレンス
ホームSystem.EventLog › EvtExportLog

EvtExportLog

関数
条件に合うイベントをファイルへエクスポートする。
DLLwevtapi.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL EvtExportLog(
    EVT_HANDLE Session,   // optional
    LPCWSTR Path,   // optional
    LPCWSTR Query,   // optional
    LPCWSTR TargetFilePath,
    DWORD Flags
);

パラメーター

名前方向
SessionEVT_HANDLEinoptional
PathLPCWSTRinoptional
QueryLPCWSTRinoptional
TargetFilePathLPCWSTRin
FlagsDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL EvtExportLog(
    EVT_HANDLE Session,   // optional
    LPCWSTR Path,   // optional
    LPCWSTR Query,   // optional
    LPCWSTR TargetFilePath,
    DWORD Flags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("wevtapi.dll", SetLastError = true, ExactSpelling = true)]
static extern bool EvtExportLog(
    IntPtr Session,   // EVT_HANDLE optional
    [MarshalAs(UnmanagedType.LPWStr)] string Path,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string Query,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string TargetFilePath,   // LPCWSTR
    uint Flags   // DWORD
);
<DllImport("wevtapi.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EvtExportLog(
    Session As IntPtr,   ' EVT_HANDLE optional
    <MarshalAs(UnmanagedType.LPWStr)> Path As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> Query As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> TargetFilePath As String,   ' LPCWSTR
    Flags As UInteger   ' DWORD
) As Boolean
End Function
' Session : EVT_HANDLE optional
' Path : LPCWSTR optional
' Query : LPCWSTR optional
' TargetFilePath : LPCWSTR
' Flags : DWORD
Declare PtrSafe Function EvtExportLog Lib "wevtapi" ( _
    ByVal Session As LongPtr, _
    ByVal Path As LongPtr, _
    ByVal Query As LongPtr, _
    ByVal TargetFilePath As LongPtr, _
    ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

EvtExportLog = ctypes.windll.wevtapi.EvtExportLog
EvtExportLog.restype = wintypes.BOOL
EvtExportLog.argtypes = [
    ctypes.c_ssize_t,  # Session : EVT_HANDLE optional
    wintypes.LPCWSTR,  # Path : LPCWSTR optional
    wintypes.LPCWSTR,  # Query : LPCWSTR optional
    wintypes.LPCWSTR,  # TargetFilePath : LPCWSTR
    wintypes.DWORD,  # Flags : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('wevtapi.dll')
EvtExportLog = Fiddle::Function.new(
  lib['EvtExportLog'],
  [
    Fiddle::TYPE_INTPTR_T,  # Session : EVT_HANDLE optional
    Fiddle::TYPE_VOIDP,  # Path : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # Query : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # TargetFilePath : LPCWSTR
    -Fiddle::TYPE_INT,  # Flags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "wevtapi")]
extern "system" {
    fn EvtExportLog(
        Session: isize,  // EVT_HANDLE optional
        Path: *const u16,  // LPCWSTR optional
        Query: *const u16,  // LPCWSTR optional
        TargetFilePath: *const u16,  // LPCWSTR
        Flags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("wevtapi.dll", SetLastError = true)]
public static extern bool EvtExportLog(IntPtr Session, [MarshalAs(UnmanagedType.LPWStr)] string Path, [MarshalAs(UnmanagedType.LPWStr)] string Query, [MarshalAs(UnmanagedType.LPWStr)] string TargetFilePath, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wevtapi_EvtExportLog' -Namespace Win32 -PassThru
# $api::EvtExportLog(Session, Path, Query, TargetFilePath, Flags)
#uselib "wevtapi.dll"
#func global EvtExportLog "EvtExportLog" sptr, sptr, sptr, sptr, sptr
; EvtExportLog Session, Path, Query, TargetFilePath, Flags   ; 戻り値は stat
; Session : EVT_HANDLE optional -> "sptr"
; Path : LPCWSTR optional -> "sptr"
; Query : LPCWSTR optional -> "sptr"
; TargetFilePath : LPCWSTR -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "wevtapi.dll"
#cfunc global EvtExportLog "EvtExportLog" sptr, wstr, wstr, wstr, int
; res = EvtExportLog(Session, Path, Query, TargetFilePath, Flags)
; Session : EVT_HANDLE optional -> "sptr"
; Path : LPCWSTR optional -> "wstr"
; Query : LPCWSTR optional -> "wstr"
; TargetFilePath : LPCWSTR -> "wstr"
; Flags : DWORD -> "int"
; BOOL EvtExportLog(EVT_HANDLE Session, LPCWSTR Path, LPCWSTR Query, LPCWSTR TargetFilePath, DWORD Flags)
#uselib "wevtapi.dll"
#cfunc global EvtExportLog "EvtExportLog" intptr, wstr, wstr, wstr, int
; res = EvtExportLog(Session, Path, Query, TargetFilePath, Flags)
; Session : EVT_HANDLE optional -> "intptr"
; Path : LPCWSTR optional -> "wstr"
; Query : LPCWSTR optional -> "wstr"
; TargetFilePath : LPCWSTR -> "wstr"
; Flags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wevtapi = windows.NewLazySystemDLL("wevtapi.dll")
	procEvtExportLog = wevtapi.NewProc("EvtExportLog")
)

// Session (EVT_HANDLE optional), Path (LPCWSTR optional), Query (LPCWSTR optional), TargetFilePath (LPCWSTR), Flags (DWORD)
r1, _, err := procEvtExportLog.Call(
	uintptr(Session),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Path))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Query))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetFilePath))),
	uintptr(Flags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function EvtExportLog(
  Session: NativeInt;   // EVT_HANDLE optional
  Path: PWideChar;   // LPCWSTR optional
  Query: PWideChar;   // LPCWSTR optional
  TargetFilePath: PWideChar;   // LPCWSTR
  Flags: DWORD   // DWORD
): BOOL; stdcall;
  external 'wevtapi.dll' name 'EvtExportLog';
result := DllCall("wevtapi\EvtExportLog"
    , "Ptr", Session   ; EVT_HANDLE optional
    , "WStr", Path   ; LPCWSTR optional
    , "WStr", Query   ; LPCWSTR optional
    , "WStr", TargetFilePath   ; LPCWSTR
    , "UInt", Flags   ; DWORD
    , "Int")   ; return: BOOL
●EvtExportLog(Session, Path, Query, TargetFilePath, Flags) = DLL("wevtapi.dll", "bool EvtExportLog(int, char*, char*, char*, dword)")
# 呼び出し: EvtExportLog(Session, Path, Query, TargetFilePath, Flags)
# Session : EVT_HANDLE optional -> "int"
# Path : LPCWSTR optional -> "char*"
# Query : LPCWSTR optional -> "char*"
# TargetFilePath : LPCWSTR -> "char*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。