1

現在、ユーザーのIISインストールから「Webサイト」のリストを要求するInnoスクリプトインストーラーを作成しようとしています。これにより、ユーザーはコンボボックスリストから適切なWebサイトを選択でき、このリストを使用してで仮想ディレクトリを作成できます。正しいWebサイトの場所。

コンボボックスに入力する「デフォルトのWebサイト」などのIISWebサイトのリストを生成する必要があります

これまでのところ、次のコードを使用してハードコードされたコンボボックスの選択に基づいた場所に仮想ディレクトリをインストールすることしかできませんでした。

[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で持っている利用可能なWebサイトからアイテムを動的に設定することです...

助けてくれてありがとう!

4

3 に答える 3

2

実際、私は昨日これを「解決」しましたが、まだこのテーマについて他に何も見つからなかったので、私たちはパイオニアだと思います;)。私はあなたがした長い行を始めましたが、有用なドキュメントが見つからなかったので、別の道を進みました。私の解決策は機能しますが、それは非常に厄介です。

基本的に、Webサイトのリストをテキストファイルに出力する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;
于 2011-03-30T07:28:53.600 に答える
2

朗報!! 私たちが探していた隠されたものを見つけました。それを修正するために別の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行を.Nameではなく.ServerCommentに変更することでした。

楽しみ :)

Stu

于 2011-03-30T22:34:43.003 に答える
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に接続し、Webサーバー名を一覧表示します。どういうわけかそれらはIDとして出てきます:(

また、2番目の関数(getwebsite)が必要になることもありませんでした

MSDNは、名前をオーバーライドしてキーを表示できると述べていますが、詳しくは説明していません。それがエラーの場合、名前がオーバーライドされる可能性のある場所を見つけようとしています。 http://msdn.microsoft.com/en-us/library/ms525545%28VS.90%29.aspx

于 2011-03-30T02:51:16.653 に答える