ホーム › System.EventLog › EvtClearLog
EvtClearLog
関数イベントログを消去し任意でバックアップする。
シグネチャ
// wevtapi.dll
#include <windows.h>
BOOL EvtClearLog(
EVT_HANDLE Session, // optional
LPCWSTR ChannelPath,
LPCWSTR TargetFilePath, // optional
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Session | EVT_HANDLE | inoptional |
| ChannelPath | LPCWSTR | in |
| TargetFilePath | LPCWSTR | inoptional |
| Flags | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// wevtapi.dll
#include <windows.h>
BOOL EvtClearLog(
EVT_HANDLE Session, // optional
LPCWSTR ChannelPath,
LPCWSTR TargetFilePath, // optional
DWORD Flags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("wevtapi.dll", SetLastError = true, ExactSpelling = true)]
static extern bool EvtClearLog(
IntPtr Session, // EVT_HANDLE optional
[MarshalAs(UnmanagedType.LPWStr)] string ChannelPath, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string TargetFilePath, // LPCWSTR optional
uint Flags // DWORD
);<DllImport("wevtapi.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EvtClearLog(
Session As IntPtr, ' EVT_HANDLE optional
<MarshalAs(UnmanagedType.LPWStr)> ChannelPath As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> TargetFilePath As String, ' LPCWSTR optional
Flags As UInteger ' DWORD
) As Boolean
End Function' Session : EVT_HANDLE optional
' ChannelPath : LPCWSTR
' TargetFilePath : LPCWSTR optional
' Flags : DWORD
Declare PtrSafe Function EvtClearLog Lib "wevtapi" ( _
ByVal Session As LongPtr, _
ByVal ChannelPath 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
EvtClearLog = ctypes.windll.wevtapi.EvtClearLog
EvtClearLog.restype = wintypes.BOOL
EvtClearLog.argtypes = [
ctypes.c_ssize_t, # Session : EVT_HANDLE optional
wintypes.LPCWSTR, # ChannelPath : LPCWSTR
wintypes.LPCWSTR, # TargetFilePath : LPCWSTR optional
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')
EvtClearLog = Fiddle::Function.new(
lib['EvtClearLog'],
[
Fiddle::TYPE_INTPTR_T, # Session : EVT_HANDLE optional
Fiddle::TYPE_VOIDP, # ChannelPath : LPCWSTR
Fiddle::TYPE_VOIDP, # TargetFilePath : LPCWSTR optional
-Fiddle::TYPE_INT, # Flags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "wevtapi")]
extern "system" {
fn EvtClearLog(
Session: isize, // EVT_HANDLE optional
ChannelPath: *const u16, // LPCWSTR
TargetFilePath: *const u16, // LPCWSTR optional
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 EvtClearLog(IntPtr Session, [MarshalAs(UnmanagedType.LPWStr)] string ChannelPath, [MarshalAs(UnmanagedType.LPWStr)] string TargetFilePath, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'wevtapi_EvtClearLog' -Namespace Win32 -PassThru
# $api::EvtClearLog(Session, ChannelPath, TargetFilePath, Flags)#uselib "wevtapi.dll"
#func global EvtClearLog "EvtClearLog" sptr, sptr, sptr, sptr
; EvtClearLog Session, ChannelPath, TargetFilePath, Flags ; 戻り値は stat
; Session : EVT_HANDLE optional -> "sptr"
; ChannelPath : LPCWSTR -> "sptr"
; TargetFilePath : LPCWSTR optional -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "wevtapi.dll"
#cfunc global EvtClearLog "EvtClearLog" sptr, wstr, wstr, int
; res = EvtClearLog(Session, ChannelPath, TargetFilePath, Flags)
; Session : EVT_HANDLE optional -> "sptr"
; ChannelPath : LPCWSTR -> "wstr"
; TargetFilePath : LPCWSTR optional -> "wstr"
; Flags : DWORD -> "int"; BOOL EvtClearLog(EVT_HANDLE Session, LPCWSTR ChannelPath, LPCWSTR TargetFilePath, DWORD Flags)
#uselib "wevtapi.dll"
#cfunc global EvtClearLog "EvtClearLog" intptr, wstr, wstr, int
; res = EvtClearLog(Session, ChannelPath, TargetFilePath, Flags)
; Session : EVT_HANDLE optional -> "intptr"
; ChannelPath : LPCWSTR -> "wstr"
; TargetFilePath : LPCWSTR optional -> "wstr"
; Flags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wevtapi = windows.NewLazySystemDLL("wevtapi.dll")
procEvtClearLog = wevtapi.NewProc("EvtClearLog")
)
// Session (EVT_HANDLE optional), ChannelPath (LPCWSTR), TargetFilePath (LPCWSTR optional), Flags (DWORD)
r1, _, err := procEvtClearLog.Call(
uintptr(Session),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ChannelPath))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetFilePath))),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction EvtClearLog(
Session: NativeInt; // EVT_HANDLE optional
ChannelPath: PWideChar; // LPCWSTR
TargetFilePath: PWideChar; // LPCWSTR optional
Flags: DWORD // DWORD
): BOOL; stdcall;
external 'wevtapi.dll' name 'EvtClearLog';result := DllCall("wevtapi\EvtClearLog"
, "Ptr", Session ; EVT_HANDLE optional
, "WStr", ChannelPath ; LPCWSTR
, "WStr", TargetFilePath ; LPCWSTR optional
, "UInt", Flags ; DWORD
, "Int") ; return: BOOL●EvtClearLog(Session, ChannelPath, TargetFilePath, Flags) = DLL("wevtapi.dll", "bool EvtClearLog(int, char*, char*, dword)")
# 呼び出し: EvtClearLog(Session, ChannelPath, TargetFilePath, Flags)
# Session : EVT_HANDLE optional -> "int"
# ChannelPath : LPCWSTR -> "char*"
# TargetFilePath : LPCWSTR optional -> "char*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。