CoGetObject Example

InstallShield 2018 ยป InstallScript Language Reference

/*-----------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the CoGetObject function.

*

* This example shows how to create a virtual

* directory on IIS server.

*

\*-----------------------------------------------------------*/

 

#include "ifx.h"

 

#define VIRTUALDIR "My Virtual Dir"

#define VIRTUALDIRPATH "c:\inetpub\wwwroot\MyDir"

 

function OnBegin()

OBJECT objIIS_Root, objVirtDir;

 

begin

 

  set objIIS_Root = CoGetObject("IIS://localhost/W3SVC/1/Root", "");

  if (IsObject(objIIS_Root)) then

      try

        set objVirtDir = objIIS_Root.Create("IISWebVirtualDir", VIRTUALDIR);

        if (IsObject(objVirtDir)) then

          objVirtDir.Path = VIRTUALDIRPATH;

          objVirtDir.AccessRead = TRUE;

          objVirtDir.AccessScript = TRUE;

          objVirtDir.SetInfo();

          objVirtDir.AppCreate(TRUE);

          objVirtDir.SetInfo();

       endif;

    catch

      MessageBox("Unable to create Virual Directory.", INFORMATION);

    endcatch;

  endif;

  

end;