const
IISServerName = 'localhost';
IISServerNumber = '1';
IISURL = 'http://127.0.0.1';
function InitializeSetup(): Boolean;
var
IIS, WebSite, WebServer, WebRoot, VDir: Variant;
ErrorCode: Integer;
begin
if MsgBox('Setup will now connect to Microsoft IIS Server ''' + IISServerName + ''' and create a virtual directory. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
Exit;
{ Create the main IIS COM Automation object }
try
IIS := CreateOleObject('IISNamespace');
except
RaiseException('Please install Microsoft IIS first.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
end;
{ Connect to the IIS server }
WebSite := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');
WebServer := WebSite.GetObject('IIsWebServer', IISServerNumber);
WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');
{ (Re)create a virtual dir }
try
WebRoot.Delete('IIsWebVirtualDir', 'innosetup');
WebRoot.SetInfo();
except
end;
VDir := WebRoot.Create('IIsWebVirtualDir', 'innosetup');
VDir.AccessRead := True;
VDir.AppFriendlyName := 'Inno Setup';
VDir.Path := 'C:\inetpub\innosetup';
VDir.AppCreate(True);
VDir.SetInfo();
MsgBox('Created virtual directory ''' + VDir.Path + '''.', mbInformation, mb_Ok);
{ Write some html and display it }
if MsgBox('Setup will now write some HTML and display the virtual directory. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
Exit;
ForceDirectories(VDir.Path);
SaveStringToFile(VDir.Path + '/index.htm', '<html><body>Inno Setup rocks!</body></html>', False);
if not ShellExec('open', IISURL + '/innosetup/index.htm', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode) then
MsgBox('Can''t display the created virtual directory: ''' + SysErrorMessage(ErrorCode) + '''.', mbError, mb_Ok);
end;