How to programmatically (in vbscript) change / set the tcp port for a site under IIS?

My programming environment includes scripts to configure my auto-exchange on a clean machine.

One step uses vbscript to configure the website in IIS, which is used to control the build.

On a specific machine, I will run apache on port 80 for a separate task.

I would like my vbscript to set the port to 8080 for the new site that it is adding.

How can i do this?

+3
source share
2 answers

You can use adsutil.vbspart of the IIS admin scripts to change this:

cscript adsutil.vbs set W3SVC / 1 / ServerBindings ": 8080:"

In the default layout, the script is in C:\Inetpub\AdminScripts\.

+2

WMI ADSI

http://www.adopenstatic.com/cs/blogs/ken/archive/2006/07/28/188.aspx

( )

    Dim objWebApp
    Dim intArraySize
    Dim arrOldBindings
    Dim arrNewBindings

Set objWebApp = GetObject("IIS://localhost/w3svc/" WebSiteID)

If isArray(objWebApp.ServerBindings) then

arrOldBindings = objWebApp.ServerBindings
    intArraySize = UBound(arrOldBindings)
    Redim arrNewBindings(intArraySize + 1)

    For i = 0 to intArraySize
    arrNewBindings(i) = arrOldBindings(i)
    Next

arrNewBindings(intArraySize + 1) = ":mydomain.com:8080:"

    objWebApp.Put "ServerBindings", (arrNewBindings)
    objWebApp.SetInfo

End If

>
+2

Source: https://habr.com/ru/post/1698859/


All Articles