- Create an IIS application.
- Create a new IIS application pool and set it's. NET version to 4.
- Set the application pool of the new application to the new application pool.
Procedure Createiisvirtualdir (); var IIS, WebSite, WebServer, WebRoot, vdir:variant; Errorcode:integer;begin {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 ', ' eipwebv4 '); Webroot.setinfo (); except end; VDir: = Webroot.create (' IIsWebVirtualDir ', ' eipwebv4 '); Vdir.accessread: = True; Vdir.accessscript: = TRUE; Vdir.appfriendlyname: = ' easy-ip Web Client '; Vdir.path: = Expandconstant (' {app} '); Try vdir.apppoolid: = ' Classic. NET AppPool '; except end; Vdir.appcreate (True); Vdir.setinfo (); end;
var global_appcmdfilepath:string; Global_isiis7:boolean; Global_websites:sitelist; global_websitename:string; global_vdir:string; Global_appcmdexitcode:integer;const iisservername = ' localhost '; Iisapplicationpoolname = ' Test Pool '; Error_not_found = 1168; error_not_supported = 50; Md_apppool_identity_type_localsystem = 0; Md_apppool_identity_type_localservice = 1; Md_apppool_identity_type_networkservice = 2; Md_apppool_identity_type_specificuser = 3; md_logon_interactive = 0; Md_logon_batch = 1; Md_logon_network = 2; Md_logon_network_cleartext = 3;function Execappcmd (params:string): Boolean;var Execsuccessfully:boolean; Resultcode:integer;begin execsuccessfully: = Exec (' cmd.exe ', '/C ' + Global_appcmdfilepath + ' + params, ', Sw_hide, ewwaituntilterminated, ResultCode); Global_appcmdexitcode: = ResultCode; Result: = execsuccessfully and (resultcode = 0); end;function CreateVirtualDirectoryForIIS6 (physicalpath:string): String;var IIS, WebService, webServer, WebRoot, VDir, vdirapp:variant; AppPools, Apppool:variant; Websiteid:string;begin WebSiteID: = Getwebsiteidbyname (Global_websitename); Create the main IIS COM Automation object. IIS: = Createoleobject (' Iisnamespace '); Get application Pools. AppPools: = IIS. GetObject (' IIsApplicationPools ', ' localhost/w3svc/apppools '); Try//Check if the application pool already exists. AppPool: = Apppools.getobject (' IIsApplicationPool ', iisapplicationpoolname); Except//Crete the application pool. Try AppPool: = apppools.create (' IIsApplicationPool ', iisapplicationpoolname); Apppool.logonmethod: = Md_logon_network_cleartext; Apppool.apppoolidentitytype: = Md_apppool_identity_type_networkservice; Apppool.setinfo (); Except Result: = ' Failed to create a apllication pool. '; Exit; End End Connect to the IIS server. WebService: = IIS. GetObject (' IIsWebService ', IISServerName + '/w3svc '); Get the website. WebServer: = Webservice.getobject (' IIsWebServer ', WebSiteID); WebRoot: = Webserver.getobject (' IIsWebVirtualDir ', ' Root '); Delete the virtual dir if it already exists. Try Webroot.delete (' IIsWebVirtualDir ', global_vdir); Webroot.setinfo (); except//An exception would be raised if there are not such a website. End Create the virtual directory. Try VDir: = webroot.create (' IIsWebVirtualDir ', global_vdir); Vdir.accessread: = True; Vdir.accessscript: = True; Vdir.appfriendlyname: = ' Test friendly name '; Vdir.path: = PhysicalPath; Vdir.appcreate (False); Vdir.setinfo (); Except Result: = ' Failed to create a virtual directory. '; Exit; End Assign the application pool to the virtual directory. Try VDir: = Webroot.getobject (' IIsWebVirtualDir ', global_vdir); Vdir.apppoolid: = Iisapplicationpoolname; Vdir.setinfo (); Except Result: = ' Failed to assign ', the application pool to the virtual directory. Exit; End;end;function CreatevirtualdirecToryForIIS7 (physicalpath:string): String;var tempfilename:string; apppoollist:string; Createapppool:boolean;begin//Delete The application if it already exists. If not Execappcmd (Format (' delete app '%s/%s "', [Global_websitename, Global_vdir]) and then BEGIN if (global_appcmdexitcod e <> error_not_found) and (Global_appcmdexitcode <> error_not_supported) THEN begin Result: = ' Failed To delete the application. ' + Geterrormessagebycode (global_appcmdexitcode); Exit; End End Check If the application pool already exists. TempFileName: = Expandconstant (' {tmp}\apppoolnames.txt '); Execappcmd (Format (' list AppPool '%s ' > '%s ', [Iisapplicationpoolname, TempFileName]); if (Loadstringfromfile (TempFileName, apppoollist)) THEN BEGIN Createapppool: = (Pos (iisapplicationpoolname, AppPoolLis T) = 0); End ELSE begin createapppool: = True; End Create the application pool. if (Createapppool) then the BEGIN if not Execappcmd (Format (' Add aPppool/name: "%s"/managedruntimeversion:v4.0 ', [iisapplicationpoolname]) THEN BEGIN Result: = ' Failed to add the Application pool. ' + Geterrormessagebycode (global_appcmdexitcode); Exit; End End Create the application. If not Execappcmd (Format (' Add App/site.name: '%s '/path: '/%s '/physicalpath: '%s '/applicationpool: '%s ', [Global_ Websitename, Global_vdir, PhysicalPath, iisapplicationpoolname]) THEN begin with Result: = ' Failed to add the application. ' + Geterrormessagebycode (global_appcmdexitcode); Exit; End Result: = "; end;
How does I create an IIS application and application pool using Innosetup script