////////////////////////////////////////////////////////////////////////////////
//                                                                            
//  IIIIIII SSSSSS                                                            
//    II    SS                          InstallShield (R)                     
//    II    SSSSSS      (c) 1996-2002, InstallShield Software Corporation     
//    II        SS                     All rights reserved.             
//  IIIIIII SSSSSS                  
//                                                                            
//                                                                            
//  This template script provides the code necessary to build an entry-point 
//  function to be called in an InstallScript custom action. 
//                                                                            
//                                                                            
//    File Name:  Setup.rul                                                   
//                                                                            
//  Description:  InstallShield script                                        
//
////////////////////////////////////////////////////////////////////////////////

// Include Ifx.h for built-in InstallScript function prototypes, for Windows 
// Installer API function prototypes and constants, and to declare code for 
// the OnBegin and OnEnd events.
#include "ifx.h"
#include "Decl.h" 

    // The keyword export identifies MyFunction() as an entry-point function.
    // The argument it accepts must be a handle to the Installer database.
    
    export prototype InstallCDAutoUpgraderService (HWND); 
    export prototype RemoveCDAutoUpgraderService  (HWND); 
    export prototype StartCDAutoUpgraderService(HWND);   
    export prototype  StopCDAutoUpgraderService(HWND);
    // To Do:  Declare global variables, define constants, and prototype user-
    //         defined and DLL functions here.
 

// To Do:  Create a custom action for this entry-point function:
// 1.  Right-click on "Custom Actions" in the Sequences/Actions view.
// 2.  Select "Custom Action Wizard" from the context menu.
// 3.  Proceed through the wizard and give the custom action a unique name.
// 4.  Select "Run InstallScript code" for the custom action type, and in
//     the next panel select "MyFunction" (or the new name of the entry-
//     point function) for the source. 
// 5.  Click Next, accepting the default selections until the wizard 
//     creates the custom action.
//
// Once you have made a custom action, you must execute it in your setup by 
// inserting it into a sequence or making it the result of a dialog's 
// control event.

///////////////////////////////////////////////////////////////////////////////
//                                                                           
// Function:  MyFunction
//                                                                           
//  Purpose:  This function will be called by the script engine when 
//            Windows(TM) Installer executes your custom action (see the "To 
//            Do," above).
//                                                                           
///////////////////////////////////////////////////////////////////////////////
function InstallCDAutoUpgraderService(hMSI)   
    // To Do:  Declare local variables. 
     number ret,nBuffer;
     string szProgram,val,szCmdLine;
begin  

     
     
    nBuffer = 256;    
     
     MsiGetProperty(hMSI,"CustomActionData",val,nBuffer); 
                                                                                                            
                                                                                                            
                                                                                                                
     //ret = ServiceAddService ( "ReadersListener", "Oblicore - ReadersListener", "Manages events detection and alerts sending in Oblicore Guarantee.", TARGETDIR ^ "bin\\AdaptersListener.exe", FALSE, "" );                                                                                                            
     
     ret = ServiceAddService ( CDAUTO_SERVICE_NAME, CDAUTO_SERVICE_NAME, CDAUTO_SERVICE_DESC,val^"apt\\RHSrvAny.exe", FALSE, "" ); 
     ret = LaunchAppAndWait   ("sc.exe","config " + CDAUTO_SERVICE_NAME+ "  start= auto " ,  LAAW_OPTION_HIDDEN |LAAW_OPTION_WAIT);	
   	
   	

end;        

function RemoveCDAutoUpgraderService(hMSI)   
    // To Do:  Declare local variables. 
     number ret,nBuffer;
     string szProgram,val,szCmdLine;
begin       
                        
     ServiceStopService(CDAUTO_SERVICE_NAME);
     nBuffer = 256;    
     MsiGetProperty(hMSI,"CustomActionData",val,nBuffer); 
    
    // To Do:  Write script that will be executed when MyFunction is called.  
   //  val = SUPPORTDIR;
      ret = ServiceRemoveService(CDAUTO_SERVICE_NAME);
	     
end;

function StartCDAutoUpgraderService(hMSI) 

begin     
		  
		 // MessageBox ("Test",1);
		  ServiceStartService(CDAUTO_SERVICE_NAME,""); 
		 
		  
end;

function StopCDAutoUpgraderService(hMSI)   
  string szProgram,szCmdLine;    
  number ret;
begin    
        szProgram = "NET.exe";
        szCmdLine = "stop RHEV-apt";
    	ret =  LaunchAppAndWait (szProgram,szCmdLine, LAAW_OPTION_WAIT |LAAW_OPTION_HIDDEN );

end;   

  