Login :: Register
General Topics
HostedbyMaximumASP170x35
2005 IIS MVPs
Other IIS Sites
  How can I get a listing of all the log file directories and if they exist or not? 

How can I get a listing of all the log file directories and if they exist or not?

This simple script will show you the log file directory for all of the services and all of the sites.

Example Output:

W3SVC C:\WINNT\System32\LogFiles Valid Path
W3SVC\1 Default Web Site C:\WINNT\System32\LogFiles Valid Path
W3SVC\2 Administration Web Site C:\WINNT\System32\LogFiles Valid Path
W3SVC\3 Finance Web Site C:\WINNT\System32\LogFiles Valid Path
W3SVC\4 Marketing Web Site C:\WINNT\System32\LogFiles Valid Path
W3SVC\5 Sales Web site C:\WINNT\System32\LogFiles Valid Path
       
MSFTPSVC C:\WINNT\System32\LogFiles Valid Path
MSFTPSVC\1 Default FTP Site C:\WINNT\System32\LogFiles Valid Path
       
NNTPSVC C:\WINNT\System32\LogFiles Valid Path
       
SMTPSVC C:\WINNT\System32\LogFiles Valid Path
Option Explicit

Dim Servername

Const WinDir = "%WinDir%"

function ExpandPath(Path)
	Dim key, ShellObject

	if (left(Path, 8) = WinDir) then
		Set ShellObject = WScript.CreateObject("WScript.Shell")
		Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\PathName"
		ExpandPath = ShellObject.RegRead(Key) & mid(Path,9)
		Set ShellObject = Nothing
	else
		ExpandPath = Path
	end if
end function


function FormatValue(Value, MinWidth, AlignLeft)
   Dim Str

   Str = "                                       "
   Value = cStr(Value)

  if (Len(Value) < MinWidth) then
   if (AlignLeft = true) then
      FormatValue = Value+ left(Str, MinWidth-Len(Value))
   else
       FormatValue = left(Str, MinWidth-Len(Value)) & Value
  end if
else
   FormatValue = Value
  end if
end function

Sub ShowLogFolderStatus(Parent, Service, Entry)

	Dim FSO, Exists, LogDir, Name

	Set FSO = CreateObject("Scripting.FileSystemObject")
	if (Parent = true) then
		Logdir = Entry.LogfileDirectory
	else
		Logdir = Entry.LogfileDirectory & "/" & Service & Entry.Name
	end if
	LogDir = ExpandPath(LogDir)
	if (FSO.FolderExists(LogDir) = true) then
	   Exists = "Valid Path"
	else
	   Exists = "** INVALID Path ***"
	end if
	if (Parent = true) then
	    Name = Service
	else
		Name = Service & "\" & Entry.Name
	end if
	WScript.Echo FormatValue(Name, 11, true) & " " & FormatValue(Entry.ServerComment, 25, true) & _
		" " & FormatValue(LogDir, 40, true) & " " & Exists
	Set FSo=Nothing
end Sub

Sub DoWork(Service, ServiceClass)
	Dim Key, IISOBJ, Entry

	Key = "IIS://" & Servername &"/" & Service
	on error resume next
	Set IISOBJ = GetObject(Key)
	if (Err <> 0) then
		WScript.Echo "Error unable to open IIS Metabase key : " & Key & ", Err = " & Err & _
		     ", Desc = " & Err.Description
		exit sub
	end if
	WScript.Echo 
	ShowLogFolderStatus true, Service, IISOBJ
	for each Entry in IISOBJ
	   if (Entry.Class = ServiceClass) then			
			ShowLogFolderStatus false, Service, Entry
	   end if
	next
end sub

Servername = "LocalHost"
DoWork "W3SVC", "IIsWebServer"
DoWork "MSFTPSVC", "IIsFtpServer"
 This site and its contents are Copyright 1999-2004 by IISFAQ Microsoft Corporation in no way endorses or is affiliated with IISFAQ