I have a PowerShell script where I am reading and editing registry.
I tried running it manually, calling it from command line, converting it to an .exe with ps2exe, and for all of those scenarios it works as intended. However, when I package it with my installer (using MS Visual Studio Installer Projects) and try running it as Custom Actions/Commit/script.exe, it suddenly cannot find the registry keys.
Here's a snippet of my script.
## initializing new variables
$req_path = Get-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Excel\Options" |
Select-Object -ExpandProperty Property
echo $req_path
ERROR: Get-Item : Cannot find path 'HKCU:\SOFTWARE\Microsoft\Office\16.0\Excel\Options' because it doesnot exist.
I have also tried this variation to no avail:
$req_path = Get-Item -Path Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Excel\Options |
Select-Object -ExpandProperty Property
Since this is part of the installer, it runs as admin, so privileges are not the culprit.
So, How can I access the registry keys when running a PowerShell script as a custom action?
Some additional info.:
[Environment]::Is64BitProcessreturnsTrueWhoAmIreturnsnt authority\system
Considering that I am not an expert in powershell, there is a great chance that there is a better way or at least my implementation is not the most efficient one, but I found a way.