Hard time with Java installer

Could somebody assist me with the below scirpt. When I run it against the machine. It doesn’t install whatsoever. Also, I get this error below
Cannot find a process with the name “jre-7u45-windows-x64”. Verify the process name and call the cmdlet again. If Java is already installed would I have to uninstall it first before pushing the update?
Thanks for the help…
+ CategoryInfo : ObjectNotFound: (jre-7u45-windows-x64:String) [Get-Process], ProcessCommandException
+ FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand

function InstallJava {
param([String]$strComputer, $objFile, $sysArch, $antiarch)

write-host ""
write-host "Security Installer"
write-host ""

$JavaName = [string]$objFile.name
$JavaExt = $objFile.extension
$JavaFullName = $objFile.FullName
$JavaProc = ($JavaName.trimend(".exe"))
write-host $JavaProc

$JavaProc = [string]$JavaProc

    if (($JavaName -Notmatch $sysArch) -and ($JavaName -match $antiarch))
    {
    return
    }
    
    if ($JavaName -match "ia64")
    {
    return
    }

copy-item $JavaFullName \\$strComputer\c$\$JavaName -force
      
$install = (([WMICLASS]"\\$strComputer\ROOT\CIMV2:win32_process").Create("cmd /c c:\$JavaName /s"))

start-sleep -Seconds 5
                    
$javatest = get-process -cn $strComputer -name "$JavaProc"
                    
    while ($javatest -ne $null)
    {
    start-sleep -seconds 1
    write-host "waiting for java install to complete"
    $javatest = get-process -cn $strComputer -name "$JavaProc" 

    }

<#
$javatest = get-process -cn target1 -name “trustedinstaller.exe” -ea silentlycontinue

    while ($javatest -ne $null)
    {
    start-sleep -seconds 1
    #write-host "waiting for install to complete"
    $javatest = get-process -cn target1 -name "trustedinstaller.exe" -ea silentlycontinue 
    }

#>

}

Sorry you’re not getting an answer to this - I don’t think any of us are familiar enough with the Java installer to provide an answer for you.

Couple things you could try:

  • Don't bother wrapping the command in "cmd /c". The Java installer is already an executable, so just launch it directly.
  • Win32_Process.Create(), if successful, gives you the process ID that was launched. It's probably going to be more reliable to search for it by ID rather than by Name later.
  • Find out if there's a parameter you can pass to the java installer to create a log file, which you can review later to see if it's telling you why it failed.

Something along these lines:

# ... snip

$install = (([WMICLASS]"\\$strComputer\ROOT\CIMV2:win32_process").Create("c:\$JavaName /s"))

# Test for the return value here to make sure the method was successful
if ($install.ReturnValue -ne 0)
{
    throw New-Object System.ComponentModel.Win32Exception([int]$install.ReturnValue)
}

do
{
    Start-Sleep -Seconds 1
    
    try
    {
        # Using the process ID for the search instead of the name.
        $process = Get-Process -ComputerName $strComputer -Id $install.ProcessId -ErrorAction Stop
    }
    catch
    {
        if ($_.FullyQualifiedErrorId -match 'NoProcessFoundForGivenId')
        {
            break
        }
        else
        {
            throw
        }
    }
} while ($process -ne $null)