如何在一个vbs中判断虚拟目录是否已经存在.

请大家帮忙,急用,
---------------------------------------------------------------

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"

Published At
Categories with Web编程
comments powered by Disqus