`
hipeace87
  • 浏览: 174386 次
  • 性别: Icon_minigender_1
  • 来自: 山东菏泽
社区版块
存档分类
最新评论

批处理创建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%"表示当前目录
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics