IServices

Declaration

IServices : IDispatch

Overview

This interface is meant to add new service operation or delete/edit the existing ones.

Properties

Array<IBaseServiceOperation> ServiceOperations - Gets the collection of project service operations.

Methods

NewServiceInstallOperation(IFile aServiceSourceFile) returns IServiceInstallOperation
Creates a new service install operation. Automatically adds a service control operation for the new service.

NewServiceControlOperation(String aServiceName) returns IServiceControlOperation
Creates a new service control operation.

NewServiceConfigureOperation(String aServiceName) returns IServiceConfigureOperation
Creates new service configure operation.

NewServiceFailureOperation(String aServiceName) returns IServiceFailureOperation
Creates new service configure operation.

DeleteServiceOperation(IBaseServiceOperation aOperation)
Deletes a service operation.

Example

$advinst = new-object -com AdvancedInstaller
$prj = $advinst.LoadProject("D:\services.aip")

# Add new service install operation
$serviceInstall = $prj.Services.ServiceOperations | where {$_.Name -eq "MyService" -and $_.OperationType -eq "Service Install"}[0]

if($serviceInstall -eq $null)
{
  $serviceExe = $prj.FilesComponent.Files | where {$_.Name -eq "MyService.exe"}[0]
  if($serviceExe -eq $null)
  {
      $serviceExe = $prj.FilesComponent.AddFileS("appdir", "D:\my_app_folder\MyService.exe")
  }

  $serviceInstall = $prj.Services.NewServiceInstallOperation($serviceExe)
  $serviceInstall.Name = "MyService"
}

$serviceInstall.AllowDesktopInteraction = $true
$serviceInstall.Arguments = "/Run"
$serviceInstall.StartType = "OnDemand"

$serviceConfig = $prj.Services.ServiceOperations | where {$_.Name -eq "MySecondService" -and $_.OperationType -eq "Service Configuration"}[0]
if($serviceConfig -eq $null)
{
  $serviceConfig = $prj.Services.NewServiceConfigureOperation("MySecondService")
}

$serviceConfig.ConfigureOnInstall = $true
$serviceConfig.ConfigureOnReinstall = $true
$serviceConfig.ConfigureOnUninstall = $false
$serviceConfig.SettingToChange = "TimeToRunFailureActions"

$serviceFail = $prj.Services.ServiceOperations | where {$_.Name -eq "MySecondService" -and $_.OperationType -eq "Service Failure"}[0]
if($serviceFail -eq $null)
{
  $serviceFail = $prj.Services.NewServiceFailureOperation("MySecondService")
}

$serviceFail.ConfigureOnInstall = $true
$serviceFail.ConfigureOnReinstall = $true
$serviceFail.ConfigureOnUninstall = $false
$serviceFail.DaysBeforeResetFailureCount = 1
$serviceFail.RebootMessage = ""

$failureAction = $serviceFail.FailureActions | where {$_.Action -eq "RunProgram"}[0]
if($failureAction -eq $null)
{
  $failureAction = $serviceFail.NewFailureAction("RunProgram", 1)
}

$serviceFail.RunProgram = "MySecondService.exe"
$serviceFail.RunProgramArguments = '/log "MySecondService has stopped."'

$prj.Save()

    

See also

IBaseServiceOperation

IServiceInstallOperation

Topics