Control IIS with VBS to create virtual directories

zhaozj2021-02-16  41

Referring to INETPUB / ADMINSCRIPTS / ADSUTIL.VBS written scripts:

'// begin //

On Error Resume NextstrVirtualDirectoryName = InputBox ( "Please enter the virtual directory name") If strVirtualDirectoryName = "" Then msgbox ( "input error, the program ends!") WScript.QuitEnd IfstrVirtualDirectoryPath = InputBox ( "Please enter the directory where the file name of the site (for example, : e: / web) ") If strVirtualDirectoryPath =" "Then msgbox ("! mistake, the program ends ") WScript.QuitEnd IfstrVirtualDirectoryPath = Replace (strVirtualDirectoryPath," / "," / ") Set MyFso = CreateObject (" Scripting. FileSystemObject ") If MyFso.FolderExists (strVirtualDirectoryPath) = 0 then msgbox (" folder "& strVirtualDirectoryPath &" does not exist ") Else Set objIIS = GetObject (" IIS:! // localhost / W3SVC / 1 / Root ") Set objVirtualDirectory = objIIS .Create ( "IISWebVirtualDir", strVirtualDirectoryName) If (Err.Number <> 0) Then 'true Err.Clear Set myDir = objIIS.GetObject ( "IIsWebVirtualDir", strVirtualDirectoryName) if the virtual directory already exists or other errors' Creating a virtual directory object if (Err.Number <> 0) THEN 'virtual directory does not exist, it is true, indicating that other unknown errors, otherwise there is msgbox for the virtual directory ("Sorry, unknown error, failure!") WScript.quit (Err.Number) end if m = msgbox ("Virtual Directory" & StrvirtualDirectoryName & "Is there, is it deleted?", 1 32, "Delete Confirmation") IF M <> 1 THEN WScript.Quit end if objIIS.Delete "IIsObject", strVirtualDirectoryName If (Err.Number <> 0) Then msgbox ( "Removing Virtual Directories" & strVirtualDirectoryName & "failed") WScript.Quit (Err.Number) end if Set objVirtualDirectory = objIIS. Create ("IisWebVirtualDir", strvirtualdirectoryname) objvirtualdirectory.accessscript =

"Successful operation! Virtual directory" true objVirtualDirectory.Path = strVirtualDirectoryPath objVirtualDirectory.EnableDefaultDoc = True objVirtualDirectory.DefaultDoc = "index.htm" objVirtualDirectory.AppFriendlyName = strVirtualDirectoryName objVirtualDirectory.SetInfo objVirtualDirectory.AppCreate true 'bolInProcessApplication msgbox (& strVirtualDirectoryName & "successfully established," & vbCrLf & "Please enter in the browser address bar http: // localhost /" & strVirtualDirectoryName & "/ see the effect") else objVirtualDirectory.AccessScript = true objVirtualDirectory.Path = strVirtualDirectoryPath objVirtualDirectory.EnableDefaultDoc = True objVirtualDirectory.DefaultDoc = "index.htm" objVirtualDirectory. AppFriendlyName = strVirtualDirectoryName objVirtualDirectory.SetInfo objVirtualDirectory.AppCreate true 'bolInProcessApplication msgbox ( "the operation was successful virtual directory!" & strVirtualDirectoryName & "successfully established," & vbCrLf & "Please enter the http in the browser address bar: // localhost /" & strVirtualDirectoryName & "/ see the effect." ) End ifend ifset myfso = nothing '// end //

Refer to the above script when making a installed ASP program. The above programs can also be rewritten as an ASP script, just pay attention when running the ASP page, the anonymous login user of the virtual directory in the ASP page must be an Administrator, otherwise the browser will prompt the permissions! The same manner can also be used to create a web site, which can be referred to INETPUB / Adminscripts / Adsutil.vbs.

转载请注明原文地址:https://www.9cbs.com/read-26287.html

New Post(0)