ASP
  Home arrow ASP arrow Windows Server Hacks 12, 77, and 98
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Windows Server Hacks 12, 77, and 98
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    2004-06-14

    Table of Contents:
  • Windows Server Hacks 12, 77, and 98
  • Windows Server Hacks 77: Security FAQ
  • Windows Server Hacks 98:
  • Windows Server Hacks 98 Continued: ASR Restore

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Windows Server Hacks 12, 77, and 98


    (Page 1 of 4 )

    These tips are from the book Windows Server Hacks by Mitch Tulloch (O'Reilly Media, ISBN: 0-596-00647-0, 2004). Hack 12 deals with getting event log information. Hack 77 presents answers to common security-related FAQs, and Hack 98 talks about the Automated System Recovery (ASR), a new feature of Windows Server 2003 that makes recovering from a disaster a whole lot easier.

    windowserverhacksWindows Server Hacks 12: Get Event Log Information

    Need to check on the size and configuration settings of your event logs? Use this script instead of the GUI; it’s faster!

    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)}!"

    'append to moniker string if a machine name has been given
    If WScript.Arguments.Count = 1 Then _
    strMoniker = strMoniker & "\\" & WScript.Arguments(0) & ":"

    'attempt to connect to WMI
    Set refWMI = GetObject(strMoniker)
    If Err <> 0 Then
    WScript.Echo "Could not connect to the WMI service."
    WScript.Quit
    End If

    'get a collection of Win32_NTEventLogFile objects
    Set colEventLogs = refWMI.InstancesOf("Win32_NTEventLogFile")
    If Err <> 0 Then
    WScript.Echo "Could not retrieve Event Log objects"
    WScript.Quit
    End If

    'iterate through each log and output information
    For Each refEventLog In colEventLogs
    WScript.Echo "Information for the " & _
    refEventLog.LogfileName & _
    " log:"
    WScript.Echo " Current file size: " & refEventLog.FileSize
    WScript.Echo " Maximum file size: " & refEventLog.MaxFileSize WScript.Echo " The Log currently contains " & _ refEventLog.NumberOfRecords & " records"

    'output policy info in a friendly format using OverwriteOutDated,
    'as OverWritePolicy is utterly pointless.
    'note "-1" is the signed interpretation of 4294967295
    Select Case refEventLog.OverwriteOutDated
    Case 0 WScript.Echo _
    " Log entries may be overwritten as required"
    Case -1 WScript.Echo _
    " Log entries may NEVER be overwritten"
    Case Else WScript.Echo _
    " Log entries may be overwritten after " & _
    refEventLog.OverwriteOutDated & " days"
    WScript.Echo
    End Select
    Next

    Set refEventLog = Nothing
    Set colEventLogs = Nothing
    Set refWMI = Nothing

    Running the Hack

    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:

    C:\> cscript loginfo.vbs
    Microsoft (R) Windows Script Host Version 5.
    6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

    Information for the Security log:
    Current file size: 65536
    Maximum file size: 524288
    The Log currently contains 166
    records Log entries may be overwritten after 7 days

    Information for the Application log:
    Current file size: 524288
    Maximum file size: 524288
    The Log currently contains 2648 records
    Log entries may be overwritten as required

    Information for the System log:
    Current file size: 524288
    Maximum file size: 524288
    The Log currently contains 2648 records
    Log entries may be overwritten after 7 days

    Note that when you run this script on a domain controller, it displays information concerning the Directory Service, File Replication Service, and DNS logs as well.

    —Rod Trent 

    Buy the book!If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

    Visit O'Reilly's
    http://www.onlamp.com/security for more related content.

    More ASP Articles
    More By O'Reilly Media


     

    ASP ARTICLES

    - Using MySQL with ASP
    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT