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