Use 32-bit version of Powershell to uninstall app with MsiExec

I know exactly how to search the registry for a key with a DisplayName equal to the name of the programs, say “Symantec Endpoint Protection”. But the problem is, I don’t know whether or not the computer this will be running on is 32 bit or 64 bit. Therefore, I need to write it based on 32-bit.

My code works fine if the powershell instance is 64-bit, but it doesn’t work at all if it’s 32 bit and I can’t understand why. I know it’s not because I’m including $key2 in the search path. Are the functions I’m using 64-bit only? If so, do I have an alternative (that’s not WMI)?

[pre]

$key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
$key2="HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$valuename="Symantec Endpoint Protection"
$value=Get-ChildItem-Path $key,$key2 | Get-ItemProperty | Where-Object {
$_.DisplayName-eq$valuename
}
$value[0].PSChildName
[/pre]

what is the error you are getting ?

I believe in 32 bit Wow6432Node would be seen as the other one.

I’m not getting any errors except at the last line where it says it cannot index into a null array, which indicates that it did not find any registry entries matching my search terms.

Do you understand how registry access works from a 32-bit app? The 64-bit area isn’t accessible.

# from 64-bit powershell
New-ItemProperty hklm:\software\ bitness -value 64
New-ItemProperty hklm:\software\wow6432node bitness -value 32

(Get-ItemProperty hklm:\software\ bitness).bitness
64
(Get-ItemProperty hklm:\software\wow6432node bitness).bitness
32

# run 32-bit powershell
C:\windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

# from 32-bit powershell
# answer is 32, not 64
(Get-ItemProperty hklm:\software\ bitness).bitness
32
(Get-ItemProperty hklm:\software\wow6432node bitness).bitness
32

[quote quote=162053]Do you understand how registry access works from a 32-bit app? The 64-bit area isn’t accessible.

PowerShell
19 lines
<textarea class="ace_text-input" style="opacity: 0; height: 17.6px; width: 6.59775px; left: 51px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# from 64-bit powershell
New-ItemProperty hklm:\software\ bitness -value 64
New-ItemProperty hklm:\software\wow6432node bitness -value 32
(Get-ItemProperty hklm:\software\ bitness).bitness
64
(Get-ItemProperty hklm:\software\wow6432node bitness).bitness
32
# run 32-bit powershell
C:\windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
# from 32-bit powershell
# answer is 32, not 64
(Get-ItemProperty hklm:\software\ bitness).bitness
32
(Get-ItemProperty hklm:\software\wow6432node bitness).bitness
32
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote] I understand, I just assumed it wasn't a big deal and that it would simply skip the 64-bit part if it was a 32-bit system. I ended up just using the 32-bit path, since this application should always be found in both locations on a 64-bit machine.