Tuesday, April 29, 2014

Microsoft SCCM 2012: Java 7 Runtime (All Versions) Uninstall Package

This post will show you how to create an uninstall package for Java 7 that will uninstall all versions of Java 7 up to version 7 Update 55.  This package will call on a powershell script to handle the uninstall process.  This package will be referenced in an upcoming post and is a critical component to successfully install Java from an extracted MSI (resolves msi repair/reinstall corruption).

Java 7 Uninstaller Powershell Script

The first step in the process is to create a powershell script that will look into the registry to see which versions of Java are installed and then run an uninstall command for any version of Java 7 that is installed. 

In this case I only have the script looking for Java 7 and will create seperate uninstallers for other major Java releases.  This will allow me flexibility in those cases where I need to keep a previous major version installed for application compatibility but want to uninstall another version.  With that said, there is nothing keeping you from editing this script and adding in the proper values for Java 6, 8, etc. and having a single script that uninstalls those instances as well.

Following is a brief description of what the script does:
  1. Kill processes that may be tied to Java.  This will resolve some setup failure issues that occur if the processes are left running.
  2. Populate an array with each Java version product code.  This is where you will define new versions of Java that come out.
  3. For each code in the array check if it exists in the registry.
    1. If the product code exists perform and uninstall of Java based on that product code.
For any version of Java 7 you will find a corresponding uninstall key in the registry path HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ followed by a product code GUID.  In the case of Java 7 the product code looks like:

{26A24AE4-039D-4CA4-87B4-2F86417004FF}

I have highlighted the section of the key above that is modified with subsequent version releases.  You can easily determine the next key by modifying the highlighted values accordingly.
  1. The 6417004 in the key can be either 32 or 64 depending on whether it is referencing the 32 bit instance of Java or the 64 bit instance of Java.
  2. The internal version number for Java 7 is version 1.7.0.  This can be found in the following portion of the highlighted code 6417004.
  3. The update revision is reference in the following portion of the highlighted code 6417004.
So, in the example above you can see that the key represents the 64bit version of Java 7 (1.7.0) Update 4.

Following is the powershell script that I use.  There isn't any error catching in the script which would be handy and probably a focus on a future script update so please provide feedback.

<#
Java 7 Uninstaller

Description: This script will kill any Java dependent processes.
It will then proceed to run though an array of known Java product codes to check if they exist on the system.
If a Java instance is located this script will uninstall that instance of Java.

Written by Michael J. Wolf
Date: 2014/04/05
#>

#Kill Processes
Stop-Process -Name iexplore* -Force
Stop-Process -Name firefox* -Force
Stop-Process -Name chrome* -Force
Stop-Process -Name javaw* -Force
Stop-Process -Name jqs* -Force
Stop-Process -Name jusched* -Force

#Uninstall Java

#Java 7 Product Code Array
$JavaPCode = "{26A24AE4-039D-4CA4-87B4-2F83217000FF}", <# Java 7 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417000FF}", <# Java 7 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217001FF}", <# Java 7u1 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417001FF}", <# Java 7u1 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217002FF}", <# Java 7u2 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417002FF}", <# Java 7u2 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217003FF}", <# Java 7u3 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417003FF}", <# Java 7u3 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217004FF}", <# Java 7u4 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417004FF}", <# Java 7u4 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217005FF}", <# Java 7u5 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417005FF}", <# Java 7u5 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217006FF}", <# Java 7u6 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417006FF}", <# Java 7u6 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217007FF}", <# Java 7u7 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417007FF}", <# Java 7u7 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217009FF}", <# Java 7u9 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417009FF}", <# Java 7u9 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217010FF}", <# Java 7u10 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417010FF}", <# Java 7u10 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217011FF}", <# Java 7u11 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417011FF}", <# Java 7u11 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217013FF}", <# Java 7u13 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417013FF}", <# Java 7u13 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217015FF}", <# Java 7u15 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417015FF}", <# Java 7u15 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217017FF}", <# Java 7u17 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417017FF}", <# Java 7u17 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217021FF}", <# Java 7u21 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417021FF}", <# Java 7u21 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217025FF}", <# Java 7u25 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417025FF}", <# Java 7u25 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217040FF}", <# Java 7u40 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417040FF}", <# Java 7u40 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217045FF}", <# Java 7u45 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417045FF}", <# Java 7u45 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217051FF}", <# Java 7u51 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417051FF}", <# Java 7u51 64bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F83217055FF}", <# Java 7u55 32bit #>`
             "{26A24AE4-039D-4CA4-87B4-2F86417055FF}" <# Java 7u55 64bit #>

#Search registry for each value in the JavaPCode array.
Foreach ($PCode in $JavaPCode) {
    #If product code exists uninstall Java with that product code.
    If (Test-Path ("hklm:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $PCode)){
       Start-Process -FilePath "msiexec.exe" -ArgumentList (" /x " + $PCode + " /qn /norestart") -Wait -Passthru
    }
}

Creating the SCCM Java 7 Uninstaller package

  • In the SCCM Console go to Software Library, Application Management, Packages.  Click on Create Package.
  • Package
    • Name = Java 7 Uninstaller
    • Description = This application will uninstall all versions of the Java 7 Runtime
    • Manufacturer =
    • Language = English
    • Version = 7
    • Check This package contains source files.  Browse to the Source folder that contains the powershell script you created above.
    • Next.
  • Program Type
    • Select Standard Program, Next.
    • Standard Program
      • Name = Java 7 Uninstaller
      • Command line = powershell -ExecutionPolicy ByPass -File JavaUninstaller.ps1
      • Startup folder =
      • Run = Normal
      • Program can run = Whether or not a user is logged on
      • Next.
    • Requirements
      • Estimated disk space = Unknown
      • Maximum allowed run time = Unknown
      • Next.
  • Summary.  Next.
  • Close.
Right click on your package and distribute it to your distribution point.  After that you should be ready to go to deploy it to collections or call it from other package like your Java install package as you will see in the next post.


 

Friday, April 4, 2014

Microsoft SCCM 2012: Creating a SAS 9.X (32Bit/64Bit) Activation/Renewal Package

This post shows how to create a SAS 9.X package that is used to activate or renew a SAS 9.X installation.

Please reference the following article which provides details about silently renewing SAS 9.1/9.2/9.3/9.4 in a Windows 7 environment:

Please note that the process is the same for SAS 9.1/9.2/9.3/9.4 32Bit and 64Bit.  The only difference is the path to the sasrenew executable.  I will denote path differences in the sasrenew.exe path quick reference section of this post.

Creating the SAS Activation/Renewal Package (9.2 32Bit)

  1. Go to Software Library, Application Management, Packages.
  2. Select Create Package
    1. Package
      1. Package Name = SAS 9.2 32Bit Renewal (2014-2015)
      2. Description = I usually put the license expiration and a few details here.
      3. Manufacturer = SAS
      4. Language = English
      5. Version = 9.2
      6. Check This package contains source files
      7. Your source will be the sid_files folder of your SAS software depot which should contain you sid.txt license file.
      8. Next.
    2. Program Type
      1. Select Do not create a program.  We will be creating 3 programs for this package in a bit.
      2. Next.
    3. Next
    4. Close
    5. Distribute the package to distribution point.
  3.   Creating a program for the system profile folder (SAS versions < 9.4)
    1. Select the package you just created and choose create program.
    2. Program Type
      1. Select Standard program, Next.
      2. Standard Program
        1. Name = SAS system profile folder
        2. Command line = cmd.exe /c "mkdir %windir%\system32\config\systemprofile\Documents\"
          1. This directory is needed for sasrenew to work when installed under system account credentials.  Please reference the SAS KB article referenced in the beginning for details.  If you do not create this directory you have a few more options.
            1. Change your sasv9.cfg -SASUSER path to a location where system credentials have access.
            2. Create a command line task sequence that references this package and performs a run as with an administrative account that has rights to the -SASUSER path.
        3. Program can run = Whether or not a user is logged on
        4. Next.
      3. Requirements
        1. Estimated disk space = Unknown
        2. Maximum allowed run time = Unknown
        3. Next.
      4. Next
      5. Close
  4. Creating a program to copy the sid to the sasrenew directory on the endpoint.
    1. Select the package you just created and choose create program.
    2. Program Type
      1. Select Standard program, Next.
      2. Standard Program
        1. Name = SAS sid file copy
        2. Command line = xcopy ".\*" "C:\Program Files\SAS\SASFoundation\9.2(32-bit)\core\sasinst\sasrenew" /E /C /Y
      3. Program can run = Whether or not a user is logged on
      4. Next.
    3. Requirements
      1. Check Run another program first
        1. Package = SAS 9.2 32Bit Renewal (2014-2015)
        2. Program = SAS system profile folder
      2. Check Always run this program first
      3. Estimated disk space = Unknown
      4. Maximum allowed run time = Unknown
      5. Next.
    4. Next
    5. Close
  5. Creating a program to activate/renew SAS
    1. Select the package you just created and choose create program.
    2. Program Type
      1. Select Standard program, Next.
      2. Standard Program
        1. Name = SAS 9.2 32Bit Activation
        2. Command line = "C:\Program Files\SAS\SASFoundation\9.2(32-bit)\core\sasinst\sasrenew\sasrenew.exe" -s "datafile:C:\Program Files\SAS\SASFoundation\9.2(32-bit)\core\sasinst\sasrenew\sid.txt"
      3. Program can run = Whether or not a user is logged on
      4. Next.
    3. Requirements
      1. Check Run another program first
        1. Package = SAS 9.2 32Bit Renewal (2014-2015)
        2. Program = SAS sid file copy
      2. Check Always run this program first
      3. Estimated disk space = Unknown
      4. Maximum allowed run time = Unknown
      5. Next.
    4. Next
    5. Close
  6. Deploy the SAS 9.2 32Bit Activation program to your collection(s).  There is no need to deploy the other programs, they will launch automatically when your main program sees the requirement to run the other two programs first.

Confirming SAS validation data and expiration

After you run this package on an endpoint you can confirm the SAS expiration by performing the following:
  1. Open SAS 9.2
  2. In the Editor type in the following
    1. proc setinit;
    2. alias;
    3. run;
  3. In the menu click submit (run icon)
  4. Validation data will appear in the log window

Sasrenew.exe path quick reference

  • SAS 9.2 32Bit
    • C:\Program Files\SAS\SASFoundation\9.2(32-bit)\core\sasinst\sasrenew
  • SAS 9.2 64Bit
    • C:\Program Files\SAS\SASFoundation\9.2\core\sasinst\sasrenew
  • SAS 9.3 32Bit
    • C:\Program Files\SASHome\x86\SASRenewalUtility\9.3
  • SAS 9.3 64Bit
    • C:\Program Files\SASHome\SASRenewalUtility\9.3
  • SAS 9.4 32Bit
    • C:\Program Files\SASHome\x86\SASRenewalUtility\9.4
  • SAS 9.4 64Bit
    • C:\Program Files\SASHome\SASRenewalUtility\9.4