reg value lost once compiled

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

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 7 years and 10 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.
Locked
User avatar
japolonio
Posts: 7
Last visit: Fri Jul 29, 2022 7:20 am

reg value lost once compiled

Post by japolonio »

[Codebox=powershell file=Untitled.ps1][/Codebox]

Hi! Need a little help -

When using PowerShell Studio 2016, I have a string setup like this:

$AddCoreApps = (Get-ItemProperty -Path "HKLM:SOFTWARE\Microsoft\Deployment 4" -Name AddedCoreApps).AddedCoreApps

The value either comes back "yes" or "no". Once i compile it into an exe the value comes back null when trying to run the exe on Windows 7 x64 but works fine on Windows 7 x86.

code written in V2 32 and compiled using V2 Host (Windows Forms) win32

any help would be greatly appreciated
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 20
Been upvoted: 37 times

Re: reg value lost once compiled

Post by Alexander Riedel »

The value is not lost. Your 64 bit system actually has a 64 bit and 32 bit registry. (It is a little bit more complicated but it will suffice here)
If you access the value from the 32 bit exe it will get the value.
If you do the same from a 64 bit application it simply looks at the 64 bit place which is different.

Now, depending on your case, the return is correct for a 64 bit application or you need to ALWAYS access the 32 bit node.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 20
Been upvoted: 37 times

Re: reg value lost once compiled

Post by Alexander Riedel »

Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: reg value lost once compiled

Post by jvierra »

It is also possible to write o ne value that appears, through reflection, in both registry "views".
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: reg value lost once compiled

Post by jvierra »

Here are the base rules of registry reflection:
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
User avatar
japolonio
Posts: 7
Last visit: Fri Jul 29, 2022 7:20 am

Re: reg value lost once compiled

Post by japolonio »

That makes sense. Created an extra registry key in the 64-bit node reran the executable and the value returned yes. Thank you for all your help!
This topic is 7 years and 10 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.
Locked