批处理创建IIS虚拟目录

前段时间做一个OA,做SETUP时用到了这个
现在贴出来和大家分享下

' 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

保存成VBS文件
@echo 创建虚拟目录
wscript.exe create.vbs Create 目录名称(运行时替换) "%cd%"
@echo 虚拟目录创建成功
保存成BAT文件 "%cd%"表示当前目录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值