ITeye博客

批处理创建IIS虚拟目录

hipeace87 · 2008-12-05 11:15 · 个人随笔 · Web前端 · Markdown

前段时间做一个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%"表示当前目录

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。