AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 10411
Accepted
Jim
Jim
Asked: 2009-05-21 07:42:01 +0800 CST2009-05-21 07:42:01 +0800 CST 2009-05-21 07:42:01 +0800 CST

从命令行(或 cscript)创建 IIS 网站?

  • 772

有没有办法编写 IIS 6 网站的创建脚本?我无权访问 powershell,因此必须使用常规命令或 cscript 脚本。

scripting iis
  • 3 3 个回答
  • 4345 Views

3 个回答

  • Voted
  1. Best Answer
    splattne
    2009-05-21T09:06:39+08:002009-05-21T09:06:39+08:00

    此方法适用于 Windows Server 2003 IIS 6.0:

    strComputer = "."
    Set objWMIService = GetObject _
        ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
            & strComputer & "\root\microsoftiisv2")
    
    Set objWebService = objWMIService.ExecQuery _
        ("Select * From IISWebService")
    
    arrBindings = Array(0)
    Set arrBindings(0) = _
        objWMIService.Get("ServerBinding").SpawnInstance_()
    arrBindings(0).IP = "192.168.1.1"
    arrBindings(0).Port = "80"
    arrBindings(0).Hostname = "www.example.com"
    
    For Each objItem in objWebService
        objItem.CreateNewSite "Test Site", arrBindings, _
            "c:\inetpub\wwwroot\testsite"
    Next
    

    这是指向与 Internet Information Server 6.0 上的网站相关或管理网站的 Microsoft TechNet 脚本存储库的链接。

    另一篇有用的TechNet 文章解释了如何以编程方式创建 AppPool。


    这是另一种方法,它也适用于 Windows Server 2000 (IIS 5.0)。编写一个 .vbs 文件:

    IISWebName = "Name of the Web"
    IISWebPath = "D:\Websites\MyWeb"
    IISWebHeader = "http://www.example.com"
    IISIPAddress = "10.0.0.10"
    
    Set wsShell = CreateObject("WScript.Shell") 
    wsShell.Run "iisweb.vbs /create """ & IISWebPath & """ """ & IISWebName & """ /b 80 /i """ & IISIPAddress & """" /d """ & IISWebHeader & """"
    

    如果你想添加虚拟目录,你可以这样做:

    oShell2.Run "iisvdir.vbs /create """ & IISWebName & """ pfengine ""D:\Common\engine"""
    
    • 4
  2. jammus
    2009-10-27T02:27:56+08:002009-10-27T02:27:56+08:00

    您可能还想自定义网站,而不是保留其默认设置。经过一番折腾,这就是我想出的:

    Sub CreateWebsite(name, hostName, physicalPath)
        ' Make connections to WMI, to the IIS namespace on the local machine. Then grab a reference to the WWW service 
        Dim locatorObj : set locatorObj = CreateObject("Wbemscripting.SWbemLocator") 
        Dim providerObj : set providerObj = locatorObj.ConnectServer(".", "root/MicrosoftIISv2") 
        Dim serviceObj : set serviceObj = providerObj.Get("IIsWebService='W3SVC'") 
    
        'Create a new instance as per splattne's answer
        Dim Bindings : Bindings = Array(0) 
        Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_() 
        Bindings(0).IP = "" 
        Bindings(0).Port = "80" 
        Bindings(0).Hostname = hostName
    
        ' Create the new Web site using the CreateNewSite method of the IIsWebService object. 
        Dim newSitePath : newSitePath = serviceObj.CreateNewSite(name, Bindings, physicalPath) 
    
        ' CreateNewSite returns a string reference to the created web service. To alter the settings we need to create a string which references the root virtual directory settings.
        Dim settingsPath : settingsPath = Replace(Left(newSitePath, Len(newSitePath) - 1) & "/ROOT'", "IIsWebServer","IIsWebVirtualDirSetting")
    
        ' Grab a reference to the settings
        Dim settings : set settings = providerObj.get(settingsPath)
    
        ' By comparing the settings of an existing, manually set up site, and one created with Splattne's method I realised I needed to change the following
        settings.AspEnableParentPaths = True
        settings.AccessFlags = 512
        settings.AccessRead = True
        settings.AuthAnonymous = True
        settings.AuthFlags = 5
        settings.AuthNTLM = True
        settings.AccessScript = True
        settings.AppFriendlyName = name
        settings.Put_()
    
        ' Set a custom handler for 500 errors. In this case a url called 500.asp. This is a bit hacky but it works.
        settings.HttpErrors(41).Properties_("HttpErrorCode") = 500
        settings.HttpErrors(41).Properties_("HttpErrorSubcode") = "*"
        settings.HttpErrors(41).Properties_("HandlerType") = "URL"
        settings.HttpErrors(41).Properties_("HandlerLocation") = "/500.asp"
        settings.Put_()
    
        ' Start the service
        Dim newSite: set newSite = providerObj.Get(newSitePath)
        newSite.Start
    End Sub
    
    • 1
  3. Andrew J. Brehm
    2009-05-21T07:45:22+08:002009-05-21T07:45:22+08:00

    我认为 PowerShell 确实适用于 IIS 7。您确定要 IIS 6 而不是 IIS 7?IIS 7 有 appcmd 命令,虽然有点难用,但可以工作。

    • 0

相关问题

  • IIS 6.0 (Windows Server 2003) 上的 HTTP 压缩

  • 这个 Web 服务器可以处理多少个站点?[复制]

  • 如何在 IIS 中发送响应标头?

  • IIS 优化

  • IIS 6.0 (Windows Server 2003) 备份的最佳实践?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve