1

我目前正在尝试创建一个 Inno 脚本安装程序,它从用户的 IIS 安装中请求“网站”列表,以便用户可以从组合框列表中选择适当的网站,并且该列表可用于在正确的网站位置。

我需要生成 IIS 网站列表,例如填充组合框的“默认网站”

到目前为止,我只能使用以下代码实现将虚拟目录安装到基于硬编码组合框选择的位置。

[Run]
Filename: {sys}\iisvdir.vbs; Parameters: "/create ""{code:GetWebSite}"" MyApp ""{app}\Website"""; Flags: skipifdoesntexist waituntilterminated shellexec; StatusMsg: Creating IIS Virtual Directory

[Code]
var
  WebsitePage: TWizardPage;
  ComboBox: TNewComboBox;

procedure InitializeWizard;
begin
  WebsitePage := CreateCustomPage(wpSelectComponents, 'Select which website you wish to install to',
'Which website should I install to?');
  ComboBox := TNewComboBox.Create(WebsitePage);
  ComboBox.Width := WebsitePage.SurfaceWidth;
  ComboBox.Parent := WebsitePage.Surface;
  ComboBox.Style := csDropDownList;
  ComboBox.Items.Add('Default Web Site');
  ComboBox.Items.Add('Website 1');
  ComboBox.ItemIndex := 0;
end;

function GetWebSite(Param: String): String;
begin
  { Return the selected Website }
  Result  := ComboBox.Text;
end;

我现在需要做的就是从用户在 IIS 中拥有的可用网站中动态设置项目...

谢谢你的帮助!

4

3 回答 3

2

Good news!! I found the hidden thing we've both been looking for, and you don't need a separate vb project to fix it.

Heres my code again:

[Code]
var
  WebsitePage: TWizardPage;
  ComboBox: TNewComboBox;
  IIS, WebSite, WebServer: Variant;
  IISServerIndex: Integer;

procedure InitializeWizard;
begin
  WebsitePage := CreateCustomPage(wpSelectComponents, 'Select which website you wish to install to',
'Which website should I install to?');
  ComboBox.Width := WebsitePage.SurfaceWidth;
  ComboBox.Parent := WebsitePage.Surface;
  ComboBox.Style := csDropDownList;

// ------------------------------------------------------------------------------

    IIS := CreateOleObject('IISNamespace');
WebServer := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');

IISServerIndex := 1;
try
    while True do
    begin
        WebSite := WebServer.GetObject('IIsWebServer', IISServerIndex);
        ComboBox.Items.Add(WebSite.ServerComment);
        IISServerIndex := IISServerIndex + 1;
    end;
except
end;

The answer was changing the ComboBox.Items.Add line to .ServerComment, not .Name.

Enjoy :)

Stu

于 2011-03-30T22:34:43.003 回答
2

实际上我昨天“解决了”这个问题,仍然没有找到关于这个主题的任何其他内容,所以我想我们是先驱;)。我开始了很长的路线,但我找不到任何有用的文档,所以走了另一条路。尽管我的解决方案有效,但它非常混乱。

基本上,我运行一个 VB 脚本,将网站列表输出到一个文本文件,然后将该文本文件读回 Inno 设置。下面是我目前的代码,非常粗糙,我打算在以后整理一下,并添加适当的错误处理。

网站.vbs

OPTION EXPLICIT

DIM CRLF, TAB
DIM strServer
DIM objWebService
strServer = "localhost"

CRLF = CHR( 13 ) & CHR( 10 )

' WScript.Echo "Enumerating websites on " & strServer & CRLF
SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )
EnumWebsites objWebService

SUB EnumWebsites( objWebService)
    DIM objWebServer, objWebServerRoot, strBindings

    Dim objFSO, objFolder, objShell, objTextFile, objFile
    Dim strDirectory, strFile, strText

    strFile = "website.txt"

    ' Create the File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    If objFSO.FileExists(strFile) Then
       Set objFolder = objFSO.GetFolder(strDirectory)
    Else
       Set objFile = objFSO.CreateTextFile(strFile)
       ' Wscript.Echo "Just created " & strDirectory & strFile
    End If 

    set objFile = nothing
    set objFolder = nothing

    ' ForAppending = 8 ForReading = 1, ForWriting = 2
    Const ForAppending = 8

    Set objTextFile = objFSO.OpenTextFile _
    (strFile, ForAppending, True)

    FOR EACH objWebServer IN objWebService
        IF objWebserver.Class = "IIsWebServer" THEN

            SET objWebServerRoot = GetObject(objWebServer.adspath & "/root")

            ' Writes strText every time you run this VBScript
            objTextFile.WriteLine(objWebServer.ServerComment)

        END IF
    NEXT

    objTextFile.Close
END SUB

Innosetup 脚本

[Code]
var

  WebsitePage: TWizardPage;
  ComboBox: TNewComboBox;
  WebSite: Variant;
  WebServer: Variant;
  WebRoot: Variant; 
  ErrorCode: Integer;
  ResultCode: Integer;
  Sites: AnsiString;

procedure InitializeWizard;
begin

  ExtractTemporaryFile('Website.vbs');
  if not ShellExec('', ExpandConstant('{tmp}\Website.vbs'),     '', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
    begin
      MsgBox('Oh no!:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
    end;

  if LoadStringFromFile(ExpandConstant('{tmp}\website.txt'), Sites) then
  begin
    //MsgBox(Sites, mbInformation, MB_OK);
  end else begin
    Exit; 
  end;

WebsitePage := CreateCustomPage(DataDirPage.ID, 'Select which website you wish to install to',
'Which website should the application be install to?');
  ComboBox := TNewComboBox.Create(WebsitePage);
  ComboBox.Width := WebsitePage.SurfaceWidth;
  ComboBox.Parent := WebsitePage.Surface;
  ComboBox.Style := csDropDownList;
  ComboBox.Items.Text := Sites;
  ComboBox.ItemIndex := 0;
end;
于 2011-03-30T07:28:53.600 回答
1

我对你的问题有点进一步,但我仍然没有破解它!我可以得到它出现在目录中的号码,但不是名字本身。

这是我到目前为止所拥有的。如果你设法更进一步,请告诉我你做了什么:)

[Code]
var
  WebsitePage: TWizardPage;
  ComboBox: TNewComboBox;
  IIS, WebSite, WebServer: Variant;
  IISServerIndex: Integer;

procedure InitializeWizard;
begin
  WebsitePage := CreateCustomPage(wpSelectComponents, 'Select which website you wish to install to',
'Which website should I install to?');
  ComboBox.Width := WebsitePage.SurfaceWidth;
  ComboBox.Parent := WebsitePage.Surface;
  ComboBox.Style := csDropDownList;

// ------------------------------------------------------------------------------

    IIS := CreateOleObject('IISNamespace');
    WebSite := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');
    WebServer := WebSite.GetObject('IIsWebServer', IISServerNumber);
WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');

    IISServerIndex := 1;
    try
        while True do
        begin
            WebServer := WebSite.GetObject('IIsWebServer', IISServerIndex);
            OneClickSiteComboBox.Items.Add(WebServer.Name);
            IISServerIndex := IISServerIndex + 1;
        end;
    except
    end;

抱歉,如果一两个组合框命名错误。我从我的来源复制了它,并试图将它与你的名字相匹配。它基本上连接到 IIS 并列出网络服务器名称。出于某种原因,它们以 ID 的形式出现:(

我最终也不需要第二个功能(您的 getwebsite)

MSDN提到名称可以被覆盖以显示键,但没有详细说明,如果那是错误,我会疯狂地试图找出它可能被覆盖的地方。 http://msdn.microsoft.com/en-us/library/ms525545%28VS.90%29.aspx

于 2011-03-30T02:51:16.653 回答