创建虚拟目录和移除虚拟目录
创建一个vbs文件:
创建一个虚拟目录
建立一个bat文件,其内容为:
移除虚拟目录
建立一个bat文件,其内容为:
咱们的Blog还不支持VBS和bat这种代码
' Creates\removes IIS Virtual Folders
if WScript.Arguments.Count<2 then
WScript.Echo "Wrong arguments."
WScript.Quit(0)
end if
sAction = WScript.Arguments(0)
if sAction="Create" then
if WScript.Arguments.Count<3 then
WScript.Echo "Wrong arguments."
WScript.Quit(0)
end if
sName = WScript.Arguments(1)
sPath = WScript.Arguments(2)
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
sPath = fso.GetAbsolutePathName(sPath)
If Err.Number<>0 then
Err.Clear
WScript.Echo "Can't create '" & sName & "': invalid virtual folder path."
WScript.Quit(0)
end if
Set oIIS = GetObject("IIS://localhost/W3SVC/1/Root")
If Err.Number<>0 then
Err.Clear
WScript.Echo "Error creating '" & sName & "' virtual folder: can't access IIS."
WScript.Quit(0)
end if
Set oDir = oIIS.GetObject("IISWebVirtualDir", sName)
' This will return error -2147024893 if it doesn't exist
If Err.Number=0 then
WScript.Echo "Can't create '" & sName & "': virtual folder already exists."
WScript.Quit(0)
end if
Err.Clear
Set oDir = oIIS.Create("IISWebVirtualDir", sName)
oDir.AccessScript = True
oDir.Path = sPath
oDir.SetInfo
oDir.AppCreate True
oDir.SetInfo
elseif sAction="Remove" then
sName = WScript.Arguments(1)
On Error Resume Next
Set oIIS = GetObject("IIS://localhost/W3SVC/1/Root")
If Err.Number<>0 then
Err.Clear
WScript.Echo "Error removing '" & sName & "' virtual folder: can't access IIS."
WScript.Quit(0)
end if
Set oDir = GetObject("IIS://localhost/W3SVC/1/Root/" & sName)
If Err.Number<>0 then
Err.Clear
WScript.Echo "Error removing '" & sName & "': virtual folder doesn't exist."
WScript.Quit(0)
else
Err.Clear
'No error so directory registration exists, we need to remove it
Set oIIS = GetObject("IIS://localhost/W3SVC/1")
Set oRoot = oIIS.GetObject("IIsWebVirtualDir","Root")
oRoot.Delete "IIsWebVirtualDir", sName
End if
end if
if WScript.Arguments.Count<2 then
WScript.Echo "Wrong arguments."
WScript.Quit(0)
end if
sAction = WScript.Arguments(0)
if sAction="Create" then
if WScript.Arguments.Count<3 then
WScript.Echo "Wrong arguments."
WScript.Quit(0)
end if
sName = WScript.Arguments(1)
sPath = WScript.Arguments(2)
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
sPath = fso.GetAbsolutePathName(sPath)
If Err.Number<>0 then
Err.Clear
WScript.Echo "Can't create '" & sName & "': invalid virtual folder path."
WScript.Quit(0)
end if
Set oIIS = GetObject("IIS://localhost/W3SVC/1/Root")
If Err.Number<>0 then
Err.Clear
WScript.Echo "Error creating '" & sName & "' virtual folder: can't access IIS."
WScript.Quit(0)
end if
Set oDir = oIIS.GetObject("IISWebVirtualDir", sName)
' This will return error -2147024893 if it doesn't exist
If Err.Number=0 then
WScript.Echo "Can't create '" & sName & "': virtual folder already exists."
WScript.Quit(0)
end if
Err.Clear
Set oDir = oIIS.Create("IISWebVirtualDir", sName)
oDir.AccessScript = True
oDir.Path = sPath
oDir.SetInfo
oDir.AppCreate True
oDir.SetInfo
elseif sAction="Remove" then
sName = WScript.Arguments(1)
On Error Resume Next
Set oIIS = GetObject("IIS://localhost/W3SVC/1/Root")
If Err.Number<>0 then
Err.Clear
WScript.Echo "Error removing '" & sName & "' virtual folder: can't access IIS."
WScript.Quit(0)
end if
Set oDir = GetObject("IIS://localhost/W3SVC/1/Root/" & sName)
If Err.Number<>0 then
Err.Clear
WScript.Echo "Error removing '" & sName & "': virtual folder doesn't exist."
WScript.Quit(0)
else
Err.Clear
'No error so directory registration exists, we need to remove it
Set oIIS = GetObject("IIS://localhost/W3SVC/1")
Set oRoot = oIIS.GetObject("IIsWebVirtualDir","Root")
oRoot.Delete "IIsWebVirtualDir", sName
End if
end if
创建一个虚拟目录
建立一个bat文件,其内容为:
@echo off
wscript.exe IISVirtualFolderTool.vbs Create DoPetShop "..\Samples\DoPetShop\Web"
wscript.exe IISVirtualFolderTool.vbs Create Demo_WebTransfers "..\Samples\Demo_WebTransfers"
wscript.exe IISVirtualFolderTool.vbs Create DoPetShop "..\Samples\DoPetShop\Web"
wscript.exe IISVirtualFolderTool.vbs Create Demo_WebTransfers "..\Samples\Demo_WebTransfers"
移除虚拟目录
建立一个bat文件,其内容为:
@echo off
wscript.exe IISVirtualFolderTool.vbs Remove DoPetShop
wscript.exe IISVirtualFolderTool.vbs Remove Demo_WebTransfers
wscript.exe IISVirtualFolderTool.vbs Remove DoPetShop
wscript.exe IISVirtualFolderTool.vbs Remove Demo_WebTransfers
咱们的Blog还不支持VBS和bat这种代码