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

Welcome Forums General PowerShell Q&A Use 32-bit version of Powershell to uninstall app with MsiExec

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
3 months ago.

  • Author
    Posts
  • #161888

    Participant
    Topics: 13
    Replies: 42
    Points: 243
    Rank: Participant

    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)?

    $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
  • #161894

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    what is the error you are getting ?

  • #161901
    js

    Participant
    Topics: 25
    Replies: 678
    Points: 1,629
    Helping Hand
    Rank: Community Hero

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

  • #161982

    Participant
    Topics: 13
    Replies: 42
    Points: 243
    Rank: Participant

    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.

  • #162053
    js

    Participant
    Topics: 25
    Replies: 678
    Points: 1,629
    Helping Hand
    Rank: Community Hero

    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
    
  • #162083

    Participant
    Topics: 13
    Replies: 42
    Points: 243
    Rank: Participant

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

    PowerShell
    19 lines

    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

    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.

The topic ‘Use 32-bit version of Powershell to uninstall app with MsiExec’ is closed to new replies.