Windows Server Hacks 100 Industrial-Strength Tips & Tools
Monitoring event logs is an essential part of an administrator’s job. Unfortunately, viewing event log settings and log file sizes from the GUI is cumbersome, and it would be useful to have an easier way to obtain this information.
That’s exactly what this hack is all about. You can run the script on Windows NT/2000 and later to obtain the current file size, maximum file size, and number of records, and you can overwrite settings on the Application, System, and Security logs.
The Code
Type the following script into Notepad (make sure Word Wrap is disabled) and save it with a .vbs extension as loginfo.vbs. Or, if you like, you can download the script from the O’Reilly web site.
Option Explicit
On Error Resume Next
Dim strMoniker
Dim refWMI
Dim colEventLogs
Dim refEventLog
Dim strSource
‘moniker string stub - security privilege needed to get
‘numrecords for Security log
strMoniker = “winMgmts:{(Security)}!”
…
To run the script, use Cscript.exe, the command-line version of the Windows Script Host (WSH). Simply type cscript loginfo.vbs at a command prompt from the directory in which the script resides. Here is a sample of typical output when the script runs on a Windows 2000 machine:
…
Website: www.oreilly.com | Filesize: 109kb
No of Page(s): 4
Click here to download Windows Server Hacks 100 Industrial-Strength Tips & Tools.
Related Tutorial
Tags: cscript, Windows Scripting Host, windows server, WSH
Comments
Leave a Reply