无法获取 IIS 网站列表以允许用户选择在 Inno Script 安装中使用的安装位置,请提供帮助

发布于 2024-10-20 23:12:06 字数 1105 浏览 7 评论 0原文

我目前正在尝试创建一个 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 中拥有的可用网站中的项目...

感谢您的帮助!

I am currently attempting to create an Inno script installer which requests a list of "Web sites" from a user's IIS installation so that the user can select the appropriate website from a combo box list and this list can be used to create a virtual directory in the correct Website location.

I need to Generate a list of IIS websites e.g. "Default Web Site" populating a combo box

So far I have only been able to achieve installing the virtual directory to a location based on a hard-coded combobox selection with the following code.

[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;

All I need to do now is dynamically set the items from the available Websites that the user has in IIS...

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

善良天后 2024-10-27 23:12:06

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

基本上,我运行一个 VB 脚本,将网站列表输出到一个文本文件,然后将该文本文件读回到 Inno 安装程序中。下面是我当前的代码,非常粗糙,我计划稍后对其进行整理并添加适当的错误处理。

Website.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;

Actually I "solved" this yesterday, still haven't found anything else on this subject so I guess we are pioneers ;). I started a long the lines you did but I could not find any useful documentation and so went down another path. Although my solution works it is very messy.

Basically I run a VB script that outputs the list of web sites to a text file and then read that text file back into Inno setup. Below is my current code, which is very rough, I plan to tidy it up and add appropriate error handling later.

Website.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 script

[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;
青春如此纠结 2024-10-27 23:12:06

好消息!!我发现了我们一直在寻找的隐藏的东西,并且您不需要单独的 vb 项目来修复它。

再次继承我的代码:

[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;

答案是将 ComboBox.Items.Add 行更改为 .ServerComment,而不是 .Name。

享受吧:)

斯图

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

初熏 2024-10-27 23:12:06

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

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

[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 并列出 Web 服务器名称。由于某种原因,它们以 ID 的形式出现:(

我最终也不需要第二个函数(你的 getwebsite)

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

I'm a bit further on with your problem, but I still haven't cracked it either! I can get the number it appears in the directory, but not the name itself.

Heres what I have so far. If you manage to take it further, please let me know what you did :)

[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;

Sorry if a combobox or two is named wrong. I copied it from my source and tried to match it to your names. It basically connects to IIS and lists the webserver names. For some reason they come out as ID's though :(

I also didn't end up needing a second function (your getwebsite)

MSDN mentions Name can be overridden to display keys but doesn't elaborate and I'm going crazy trying to find out where it could be getting overridden if thats is the error.
http://msdn.microsoft.com/en-us/library/ms525545%28VS.90%29.aspx

离鸿 2024-10-27 23:12:06

我已经更正了 Stu 的代码。
您必须使用 WebServer.ServerComment 而不是 WebServer.Name

[Code]
const
  IISServerName = 'localhost';
  IISServerNumber = '1';
  IISURL = 'http://127.0.0.1';

var
  WebsitePage: TWizardPage;
  ComboBox: TNewComboBox;
  IIS, WebSite, WebServer, WebRoot: Variant;
  IISServerIndex: Integer;

procedure InitializeWizard;
begin
  WebsitePage := CreateInputQueryPage(wpSelectDir, 
  'Konfiguration', 'In welche Webseite soll installiert werden?', '');
  ComboBox := TNewComboBox.Create(WebsitePage);
  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);
        ComboBox.Items.Add(WebServer.ServerComment);
        IISServerIndex := IISServerIndex + 1;
      end;
  except
  end;
  
end;

I have corrected the code from Stu.
You have to use WebServer.ServerComment instead of WebServer.Name

[Code]
const
  IISServerName = 'localhost';
  IISServerNumber = '1';
  IISURL = 'http://127.0.0.1';

var
  WebsitePage: TWizardPage;
  ComboBox: TNewComboBox;
  IIS, WebSite, WebServer, WebRoot: Variant;
  IISServerIndex: Integer;

procedure InitializeWizard;
begin
  WebsitePage := CreateInputQueryPage(wpSelectDir, 
  'Konfiguration', 'In welche Webseite soll installiert werden?', '');
  ComboBox := TNewComboBox.Create(WebsitePage);
  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);
        ComboBox.Items.Add(WebServer.ServerComment);
        IISServerIndex := IISServerIndex + 1;
      end;
  except
  end;
  
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文