无法获取IIS网站的列表,以允许用户选择设置位置以在Inno脚本设置中使用,请帮助 [英] Unable to obtain a list of IIS websites to allow user selection of setup location for use in an Inno Script setup, please help
问题描述
我目前正在尝试创建一个Inno脚本安装程序,请求用户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.
我需要生成一个IIS网站列表例如默认网站填充组合框
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;
现在我需要做的是动态设置用户在IIS中可用的网站...
All I need to do now is dynamically set the items from the available Websites that the user has in IIS...
感谢您的帮助!
推荐答案
解决这个昨天,仍然没有找到任何其他的这个问题,所以我想我们是先驱者;)。我开始了一个长的行,你做,但我找不到任何有用的文档,所以沿着另一条路径。虽然我的解决方案的工作原理是非常混乱。
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.
基本上,我运行一个VB脚本输出的网站列表到文本文件,然后读取该文本文件回Inno建立。下面是我当前的代码,这是非常粗糙,我计划整理它,并添加适当的错误处理后。
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 / p>
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;
这篇关于无法获取IIS网站的列表,以允许用户选择设置位置以在Inno脚本设置中使用,请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!