Writing to wrong registry location

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
XxQuaDxX
Posts: 7
Last visit: Thu Aug 18, 2022 6:00 am

Writing to wrong registry location

Post by XxQuaDxX »

Product, version and build: PowerShell Studio 2017 v5.4.145
32 or 64 bit version of product: 64
Operating system: Windows 7 SP1 // Windows 10
32 or 64 bit OS: 64-bit

I have run into a bug where when running an executable I created with the below code on a 64-bit machine the below code writes to the WOW6432Node hive instead of the hive indicated. When executed line-by-line via PowerShell it works without an issue, only after it's an EXE do I have this issue.

I need the key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MyCompanyName\PCID

but it's checking and creating the key:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MyCompanyName\PCID

The package target is Microsoft Windows 32 Bit // SAPIEN PowerShell V3 Host (Windows Forms). This works fine on 32 Bit machines but writes to the WOW6432Node on 64 Bit machines even though I am not telling it to write there.

Code: Select all

	Add-Type -AssemblyName PresentationFramework
	Set-Location HKLM:\
	If (Test-Path HKLM:\SOFTWARE\Microsoft\CompanyName\PCID) {
		$InstalledReason = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\CompanyName\PCID' -Name "InstalledReason" | Select-Object InstalledReason
		$textbox1.Text = $InstalledReason.InstalledReason
	} else {
		Set-Location HKLM:\
		If (!(Test-Path HKLM:\SOFTWARE\Microsoft\CompanyName)) {
			Set-Location .\SOFTWARE\Microsoft
			New-Item -Name CompanyName
		}
		Set-Location HKLM:\
		If (!(Test-Path HKLM:\SOFTWARE\Microsoft\CompanyName\PCID)) {
			Set-Location .\SOFTWARE\Microsoft\CompanyName
			New-Item -Name PCID
		}
		[System.Windows.MessageBox]::Show("Did not find a current Installed Reason", "CompanyName Purpose of Depoyment Tool")
Last edited by XxQuaDxX on Thu Dec 07, 2017 2:31 pm, edited 1 time in total.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: [BUG] Writing to wrong registry location

Post by Alexander Riedel »

It's not a bug, it is normal Windows behavior. 32 bit application registry access gets mapped to the WOW6432Node branch on a 64 bit machine.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: [BUG] Writing to wrong registry location

Post by Alexander Riedel »

Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: [BUG] Writing to wrong registry location

Post by davidc »

Because the registry is dependent on the bitness, you could use the "Native" platform which will generate a bootstrapper that will call the correct executable depending the bitness of the OS.

https://www.sapien.com/blog/2016/10/24/ ... -features/
David
SAPIEN Technologies, Inc.
User avatar
XxQuaDxX
Posts: 7
Last visit: Thu Aug 18, 2022 6:00 am

Re: Writing to wrong registry location

Post by XxQuaDxX »

Words can't express how stupid this windows feature is to me. Just ridiculous....

Of course this code will work but I can't return any data from it or use a Test-Path.

Start-Process -FilePath $env:windir\sysnative\WindowsPowerShell\v1.0\powershell.exe -ArgumentList '-Command "New-Item -Path HKLM:\SOFTWARE\MyCompanyName -Name PCID -ItemType Directory"'

I think I'll just stick with the original code and make them use x64bit since we aren't deploying x32bit machines any longer. I don't have enough faith that they'd be able to not have issues if I gave them more than one executable. Thanks for the quick reply and helping me understand this. :/

Also I love how this is exactly what I asked and would have found if I had understood the issue a bit better: https://social.technet.microsoft.com/Fo ... ow6432node
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Writing to wrong registry location

Post by Alexander Riedel »

There is an option to package it "Microsoft Windows Native". It will create a 32 and a 64 bit exe as well as a starter exe. The starter executable will then launch the correct application depending on the bit level of the OS.
Make an installer for it with PowerShell Studio and deploy the MSI.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.