'////////////////////////// begin //////////////////////////////////////////
On Error Resume Next strVirtualDirectoryName = InputBox("请输入虚拟目录名") If strVirtualDirectoryName = "" Then msgbox("输入错误,程序结束!") WScript.Quit End If strVirtualDirectoryPath=InputBox("请输入网站文件所在的目录名(例如:e:/web)") If strVirtualDirectoryPath = "" Then msgbox("输入错误,程序结束!") WScript.Quit End If strVirtualDirectoryPath = Replace(strVirtualDirectoryPath,"/","/") Set MyFso = CreateObject("Scripting.FileSystemObject") If MyFso.FolderExists(strVirtualDirectoryPath) = 0 then msgbox("文件夹"&strVirtualDirectoryPath&"不存在!") Else Set objIIS = GetObject("IIS://localhost/W3SVC/1/Root") Set objVirtualDirectory = objIIS.Create("IISWebVirtualDir",strVirtualDirectoryName) If (Err.Number <> 0) Then '如果虚拟目录已存在或有其他错误时则为真 Err.Clear Set myDir = objIIS.GetObject("IIsWebVirtualDir",strVirtualDirectoryName) '创建虚拟目录对象 If (Err.Number <> 0) Then '虚拟目录不存在时则为真,说明是其他未知错误,否则为虚拟目录已存在 msgbox("对不起,发生未知错误,操作失败!") WScript.Quit (Err.Number) end if m=msgbox ("虚拟目录"&strVirtualDirectoryName&"已存在,是否删除?",1+32,"删除确认") if m<>1 then WScript.Quit end if objIIS.Delete "IIsObject", strVirtualDirectoryName If (Err.Number <> 0) Then msgbox("删除虚拟目录"&strVirtualDirectoryName&"失败") WScript.Quit (Err.Number) end if Set objVirtualDirectory = objIIS.Create("IISWebVirtualDir",strVirtualDirectoryName) objVirtualDirectory.AccessScript = true objVirtualDirectory.Path = strVirtualDirectoryPath objVirtualDirectory.EnableDefaultDoc=True objVirtualDirectory.DefaultDoc="index.htm" objVirtualDirectory.AppFriendlyName=strVirtualDirectoryName objVirtualDirectory.SetInfo objVirtualDirectory.AppCreate true 'bolInProcessApplication msgbox("操作成功!虚拟目录"&strVirtualDirectoryName&"建立成功,"&vbCrLf&"请在浏览器地址栏中输入http://localhost/"&strVirtualDirectoryName&"/查看效果") else objVirtualDirectory.AccessScript = true objVirtualDirectory.Path = strVirtualDirectoryPath objVirtualDirectory.EnableDefaultDoc=True objVirtualDirectory.DefaultDoc="index.htm" objVirtualDirectory.AppFriendlyName=strVirtualDirectoryName objVirtualDirectory.SetInfo objVirtualDirectory.AppCreate true 'bolInProcessApplication msgbox("操作成功!虚拟目录"&strVirtualDirectoryName&"建立成功,"&vbCrLf&"请在浏览器地址栏中输入http://localhost/"&strVirtualDirectoryName&"/查看效果") end if End If Set MyFso = nothing