| Server IP : 123.56.80.60 / Your IP : 216.73.216.78 Web Server : Apache/2.4.54 (Win32) OpenSSL/1.1.1s PHP/7.4.33 mod_fcgid/2.3.10-dev System : Windows NT iZhx3sob14hnz7Z 10.0 build 14393 (Windows Server 2016) i586 User : SYSTEM ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party/win32/scripts/ |
Upload File : |
# Generate a base file name
import time, os
import win32api
import win32evtlog
def BackupClearLog(logType):
datePrefix = time.strftime("%Y%m%d", time.localtime(time.time()))
fileExists = 1
retry = 0
while fileExists:
if retry == 0:
index = ""
else:
index = "-%d" % retry
try:
fname = os.path.join(win32api.GetTempPath(), "%s%s-%s" % (datePrefix, index, logType) + ".evt")
os.stat(fname)
except os.error:
fileExists = 0
retry = retry + 1
# OK - have unique file name.
try:
hlog = win32evtlog.OpenEventLog(None, logType)
except win32evtlogutil.error, details:
print "Could not open the event log", details
return
try:
if win32evtlog.GetNumberOfEventLogRecords(hlog)==0:
print "No records in event log %s - not backed up" % logType
return
win32evtlog.ClearEventLog(hlog, fname)
print "Backed up %s log to %s" % (logType, fname)
finally:
win32evtlog.CloseEventLog(hlog)
if __name__=='__main__':
BackupClearLog("Application")
BackupClearLog("System")
BackupClearLog("Security")