I hope you're well. I am currently facing to some incomprehensible behavior which you can find the description of below.
What this code do?
- Check in 2 registry location (32 and 64 bits) for Ins_ProductVersion
- If nothing found then message displayed is Product Version: Not found!
- If value is found then display product version from Ins_ProductVersion
== Behavior descripton ==
If I use the code below into Powershell ISE, it work as expected:
Ouput provide:
- Product Version: 11.7.0.669
foreach ($path in 'HKLM:\SOFTWARE\KasperskyLab\protected\KES\environment\', 'HKLM:\SOFTWARE\WOW6432Node\KasperskyLab\protected\KES\environment\') {
try {
$hotfix = Get-ItemPropertyValue -Path $path -Name 'Ins_ProductVersion' -ErrorAction SilentlyContinue
# assuming you want to exit the loop at the first successfull 'hit'
if ($hotfix) { break }
}
catch {
#Write-Warning $_.Exception.Message
#Write-Host "Unable to find $hotfix"
}}
if ($hotfix) {write-host "- Product Version: $hotfix"}
else {write-host "- Product Version: Not found!"}
If I convert this code to exe with ps2exe, the output result is different.
ps2exe samples.ps1 test.exe
.\test.exe
.\test.exe : ERROR: Impossible de trouver une variable nomm‚e ®ÿhotfixÿ¯.
Au caractère Ligne:1 : 1
+ .\test.exe
+ ~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ERROR: Impossib...m‚e ®ÿhotfixÿ¯.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
- Product Version: Not found!
I hope you can help me to understand where the problem is :)
Thanks in advance.
LEFBE
==[ Solution ] == I found out where the problem was. The code works as expected, but my antivirus has been configured to block unsigned applications that read registry keys. Based on this, the value $ hotfix could not be obtained