16 July 2015

Running Programs as an Application Installation in SCCM 2012

Recently, I had to deploy an application, IntApp, with minimal intrusion and no reboots. Part of the process was to restart the application after a successful installation. The crux was that the application has to run under the user credentials. The app starts every time a system is logged into, but with laptops, that could have been a long time until the user actually rebooted the machine. This could also have been done as a package in which the executable would have been executed, but I wanted verification that when it was executed, it was actually running. To achieve this, I wrote two powershell scripts. The first one is the detection method and the second is the one that actually executes the app.

The detection method first makes sure the executable is installed. If it is, it then looks for the process to see if it is running. If it's running, a success is returned to SCCM. If not, nothing is returned back to SCCM, therefor SCCM interprets that as a failure and proceeds to execute the installer. If the application is not installed, it also returns a failure to SCCM.

The installation will test to see if the executable is present. If not, it automatically fail the install with an exit code 1. If it is installed, it will then test for the process. If the process is present, it will return a success code back to SCCM. If it is not, it will then run the executable and retest to make sure it is present in memory.

Here is the detection method:


 $DesktopExtension = $Env:ProgramFiles + "\IntApp\Desktop Extension\IntappTimeDesktopExtension.exe"  
 If ((Test-Path -Path $DesktopExtension) -eq $true) {  
      $ProcessActive = Get-Process -Name IntappTimeDesktopExtension -ErrorAction SilentlyContinue  
      If ($ProcessActive.ProcessName -eq "IntappTimeDesktopExtension") {  
           Write-Host "Success"  
           exit 0  
      } else {  
           exit 0  
      }  
 } else {  
      exit 0  
 }  


Here is the application installation script:


 $DesktopExtension = $Env:ProgramFiles + "\IntApp\Desktop Extension\IntappTimeDesktopExtension.exe"  
 If ((Test-Path -Path $DesktopExtension) -eq $true) {  
      $ProcessActive = Get-Process -Name IntappTimeDesktopExtension -ErrorAction SilentlyContinue  
      If ($ProcessActive.ProcessName -ne "IntappTimeDesktopExtension") {  
           Start-Process -FilePath $env:ProgramFiles"\IntApp\Desktop Extension\IntappTimeDesktopExtension.exe" -ErrorAction SilentlyContinue  
           Start-Sleep -Seconds 2  
      } else {  
           Write-Host "Success"  
           exit 0  
      }  
      $ProcessActive = Get-Process -Name IntappTimeDesktopExtension -ErrorAction SilentlyContinue  
      If ($ProcessActive.ProcessName -eq "IntappTimeDesktopExtension") {  
           Write-Host "Success"  
           exit 0  
      } else {  
           exit 0  
      }  
 } else {  
      exit 1  
 }  
   

0 comments:

Post a Comment