5

I'm currently receiving this error when installing Java SE Runtime Environment (jre8), updating used to work fine:

Searching if new version exists...
ERROR: Specified cast is not valid.
The install of jre8 was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\jre8\tools\chocolateyInstall.ps1'.
 See log for details.

Chocolatey installed 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Failures
 - jre8 (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\jre8\tools\chocolateyInstall.ps1'.
 See log for details.

chocolatey.log (I can't paste here because of the 30 000 character length limit, I've deleted the dates)

2
  • The Pastebin log file has been deleted, apparently I somehow set expiration for the paste.
    – user198350
    Commented Apr 5, 2020 at 12:37
  • I don't use Windows anymore, I can't say for certain if this is a Netbeans-related issue. But I certainly had Netbeans installed when asking.
    – user198350
    Commented Aug 4, 2023 at 9:40

4 Answers 4

3

I just had this problem. I did:

get-childitem hklm:\software\microsoft\windows\currentversion\uninstall\ |
  foreach { write-host $_.pspath; $_ } | get-itemproperty

and it choked on HKLM:\software\microsoft\windows\currentversion\uninstall\nbi-nb-base-8.2.0.0.201609300101, which is for Netbeans 8.2. I see in regedit that NoModify has "(invalid DWORD (32-bit) value)". get-itemproperty -erroraction continue has no effect.

EDIT: The Netbeans people are finally fixing this currently (not really). https://issues.apache.org/jira/browse/NETBEANS-2523

EDIT: They will probably never fix it.

4
  • The Regedit path was Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\nbi-tmcbeans-1.0.0.0.0 for me.
    – user198350
    Commented Aug 22, 2019 at 7:15
  • Deleting the NoModify value allowed installing jre8 immediately.
    – user198350
    Commented Aug 22, 2019 at 7:15
  • newbedev.com/… This link is what explained the issue and it was netbeans 8.2. issues.apache.org/jira/browse/NETBEANS-2523
    – IT_User
    Commented Dec 30, 2021 at 21:31
  • 1
    @IT_User Yes I posted that bug, and in Netbeans 12.6 it is STILL not resolved.
    – js2010
    Commented Dec 30, 2021 at 23:37
5

This error appears to be the result of Get-ItemProperty failing. From your log, the part of the script that is failing is here:

  Write-Output "Searching if new version exists..."
  $checkreg64 = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion | Where-Object { $_.DisplayName -like '*Java 8*' -and ([Version]$_.DisplayVersion) -eq $version} -ErrorAction SilentlyContinue
  $checkreg32 = Get-ItemProperty HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion | Where-Object { $_.DisplayName -like '*Java 8*' -and ([Version]$_.DisplayVersion) -eq $version} -ErrorAction SilentlyContinue

This failure occurs when Get-ItemProperty expects to read a registry key of type X and reads a key whose data doesn't match the constraints of the key type. research1 research2 research3

The solution in this case was to find the invalid key in registry (the registry paths that are queried in $checkreg64 and $checkreg32) and manually recreate it as a DWORD with value 1.

Update:

From the comments, you get "Specified cast is not valid" when querying Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*. It is possible there is an unrelated key in this location that contains an invalid subkey, causing the query against this location to fail. We should be able to parse each key individually from the Uninstall location to determine which key we're having trouble querying.

Run the below:

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | % { write-host "Key Name:" $_.PSChildName }

This should return some results, then, will return the Specified cast error. The error will occur on the key harboring the invalid subkey.

For example, if the results of the above look like this:

Key Name: fake_key_name_1
Key Name: fake_key_name_2
Key Name: fake_key_name_3
Get-ItemProperty : Specified cast is not valid.

Then the last key you were able to successfully query was fake_key_name_3. The key we could not query was the next key in the list. Open regedit and browse to the next key name (presumably, fake_key_name_4). This is where the failure is. There should be an invalid subkey here. Fix this, then run the command again. If you get no errors, you're all set. If you get more keys with errors, find and fix their invalid subkeys.

In the case of one of the linked examples I originally provided, the user would expect to find a REG_DWORD key with data = "(invalid DWORD (32-bit) value)". This is the key to fix.

12
  • Can you update the answer with full paths? I've navigated to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall in the registry editor, but I don't know how to continue from there.
    – user198350
    Commented Aug 25, 2018 at 15:13
  • For the x64 example: Run Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.DisplayName -like '*Java 8*' } | select -expandproperty PSChildName. If the result is {12345}, check for key HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{12345}\NoModify.
    – root
    Commented Aug 25, 2018 at 16:04
  • I get this error for the command: Get-ItemProperty : Specified cast is not valid. At line:1 char:1 + Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Unin ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-ItemProperty], InvalidCastException + FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
    – user198350
    Commented Aug 25, 2018 at 16:28
  • Great, we've inadvertently confirmed (at least one of) the location(s) of the problem. Manually navigate to HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\ through regedit, browsing each subkey for the one containing the DisplayName like "Java 8". That's where NoModify will be. Let me know if you'd like to move this discussion to chat.
    – root
    Commented Aug 25, 2018 at 16:32
  • The issue is that I can't effective search registry — but that's another question. I've searched for "java" in Regedit, but only entries in Notepad++ folder are found.
    – user198350
    Commented Aug 26, 2018 at 6:11
0

Here's a specific answer for the NetBeans cause of this issue in PowerShell, no manual registry traversing needed.

## Check for and fix known exception where broken registry entry breaks Uninstall querying
# https://issues.apache.org/jira/browse/NETBEANS-2523
try {
    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*,HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* -ea 0 | Out-Null
} catch [System.InvalidCastException] {
    $NetBeans = (& reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" | ?{$_ -match 'nbi\-'})
    $NetBeans | %{ If (Get-Item ($_ -Replace 'HKEY_LOCAL_MACHINE','HKLM:') -ea 0).Property -contains 'NoModify') { & reg add $_ /v NoModify /t REG_DWORD /d 0x1 /f | Out-Null } }
}
0
0

I could not get Inny's answer to work for me on Windows 10. Using Inny's code with a modification, I got it to work. I hope this helps someone else.

## Check for and fix known exception where broken registry entry breaks Uninstall querying

https://issues.apache.org/jira/browse/NETBEANS-2523

try { Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall*,HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall* -ea 0 | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |export-csv -Path c:\uninstall_3264bit_20240423.csv -NoTypeinformation

} catch [System.InvalidCastException] { $NetBeans = (& reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" | ?{$_ -match 'nbi-'}) $NetBeans | %{ If ((Get-Item ($_ -Replace 'HKEY_LOCAL_MACHINE','HKLM:') -ea 0).Property -contains 'NoModify') { & reg add $_ /v NoModify /t REG_DWORD /d 0x1 /f | Out-Null } } }

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Apr 23 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .