' Startup5.vbs ' VBScript Startup script. ' This program demonstrates how to log information to a log file. ' ' ---------------------------------------------------------------------- ' Copyright (c) 2009-2010 Richard L. Mueller ' Hilltop Lab web site - http://www.rlmueller.net ' Version 1.0 - May 5, 2009 ' Version 1.1 - June 10, 2010 - Delimit log file with ";". ' Version 1.2 - November 6, 2010 - No need to set objects to Nothing. ' ' You have a royalty-free right to use, modify, reproduce, and ' distribute this script file in any way you find useful, provided that ' you agree that the copyright owner above has no warranty, obligations, ' or liability for such use. Option Explicit Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns Dim intConstants, intTimeout, strTitle, intCount Dim strComputerName, strIP, strShare, strLogFile strShare = "\\MyServer\LogFile" strLogFile = "Domain.log" intTimeout = 20 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = CreateObject("Wscript.Network") Set objShell = CreateObject("Wscript.Shell") strComputerName = objNetwork.ComputerName strIP = Join(GetIPAddresses()) ' Log date/time, computer name, and IP address. If (objFSO.FolderExists(strShare) = True) Then On Error Resume Next Set objLogFile = objFSO.OpenTextFile(strShare & "\" _ & strLogFile, 8, True, 0) If (Err.Number = 0) Then ' Make three attempts to write to log file. intCount = 1 Do Until intCount = 3 objLogFile.WriteLine "Startup;" & Now & ";" _ & strComputerName & ";;" & strIP If (Err.Number = 0) Then intCount = 3 Else Err.Clear intCount = intCount + 1 If (Wscript.Version > 5) Then Wscript.Sleep 200 End If End If Loop On Error GoTo 0 objLogFile.Close End If End If Function GetIPAddresses() ' Based on a Michael Harris script, modified by Torgeir Bakken ' ' Returns array of IP Addresses as output ' by IPConfig or WinIPCfg... ' ' Win98/WinNT have IPConfig (Win95 doesn't) ' Win98/Win95 have WinIPCfg (WinNt doesn't) ' ' Note: The PPP Adapter (Dial Up Adapter) is ' excluded if not connected (IP address will be 0.0.0.0) ' and included if it is connected. Dim objShell, objFSO, objEnv, strWorkFile, objFile Dim arrData, intIndex, n, arrIPAddresses, arrParts Set objShell = CreateObject("wscript.shell") Set objFSO = CreateObject("scripting.filesystemobject") Set objEnv = objShell.Environment("PROCESS") If (objEnv("OS") = "Windows_NT") Then strWorkFile = objEnv("TEMP") & "\" & objFSO.GetTempName objShell.Run "%comspec% /c IPConfig >" & Chr(34) _ & strWorkFile & Chr(34), 0, True Else ' WinIPCfg in batch mode sends output to ' filename WinIPCfg.out strWorkFile = "WinIPCfg.out" objShell.Run "WinIPCfg /batch", 0, True End If Set objFile = objFSO.OpenTextFile(strWorkFile) arrData = Split(objFile. ReadAll, vbCrLf) objFile.Close objFSO.DeleteFile strWorkFile arrIPAddresses = Array() intIndex = -1 For n = 0 To UBound(arrData) If (InStr(arrData(n), "IP Address") > 0) Then arrParts = Split(arrData(n), ":") If (InStr(Trim(arrParts(1)), "0.0.0.0") = 0) Then intIndex = intIndex + 1 ReDim Preserve arrIPAddresses(intIndex) arrIPAddresses(intIndex)= Trim(CStr(arrParts(1))) End If End If Next GetIPAddresses = arrIPAddresses End Function