Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Vbscript Logging Techniques
 

Vbscript / General / Vbscript Logging Techniques

This script demonstrates script loggin techniques using text log files and the Windows event log.


Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")


strLogLocation = "C:\"

strScript = Wscript.ScriptName
strLogName = Left(strScript, Len(strScript)-4) & "Log.txt"

Set objLogFile = objFSO.OpenTextFile(strLogLocation & strLogName, 8, True)


strMsg = "Script Started"
objLogFile.WriteLine(Now & vbTab & strMsg)

strMsg = "Script Ended"
objLogFile.WriteLine(Now & vbTab & strMsg)


If Err.Number <> 0 Then
objShell.LogEvent 2,  "Error: " & strScript & vbCRLF & Err.Description
Else
objShell.LogEvent 0,  "Success: " & strScript
End If

objLog.Close

Set objLogFile = Nothing
Set objFSO = Nothing
Set objShell = Nothing





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
          - Check Remote Computer Disks
          - Encode Hardcoded Passwords
          - Generate Random Password
          - Get Machine Ip Address
          - Get Machine Ip Address From Name
          - Print All Files In A Folder
          - Run Chkdsk
          - Set All Network Adapters To Dhcp
          - Sql Server Query
          - Vbscript Logging Techniques
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers