前些日子@ccb朋友说想要看一下自动清理系统日志-AutoClearLog的源码,其实代码很简单的,就是调用了两个系统API,OpenEventLog和ClearEventLog,当然了,Open之后是需要CloseEventLog 的。
下面是相关的代码:
function KillEventLog(EventName:String):boolean; var HEvent:Hwnd; begin HEvent:=OpenEventLog(nil,pchar(EventName)); //参数1是远程服务器的UNC名,nil则是本机 if HEvent=0 then begin Result:=false; exit; end; if ClearEventLog(HEvent,nil) then //参数2是备份文件的名称,非空会备份 begin Result:=false; exit; end; result:=CloseEventLog(HEvent); end; procedure DelEventLog; begin KillEventLog('Application'); KillEventLog('System'); KillEventLog('Security'); KillEventLog('Setup'); KillEventLog('ForwardedEvents'); SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF); end;
代码随意使用!
谢谢,代码帮助很大~!