0

I have a self-extracting WinRar archive set up to run a powershell script upon completion. The script will launch, but specific commands do not give expected results.

In particular, I have the following command to find the installation path of an installed game (Risk of Rain 2).

Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | % { Get-ItemProperty $_.PsPath } | Where-Object {$_.DisplayName -like 'Risk of Rain 2'} | Select InstallLocation -ExpandProperty InstallLocation

When running the script by itself, I get the install path as expected.

F:\SteamLibrary\steamapps\common\Risk of Rain 2

When the script is launched (either before or after extraction), the command seems to run, but outputs nothing.

In testing, I removed everything but the following:

Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | % { Get-ItemProperty $_.PsPath } 

This still works, outputting a list of installed applications. When I add the pipe to the "Where-Object" portion, it starts to fail.

My only guess is that WinRar is starting the scripts with some other parameters set.

I tried having Winrar start a .bat that will then run the .ps1 file, but had the same result. Same goes for running the archive as an administrator.

Is something funky with my powershell script, or am I just missing something with how Winrar handles things?

Thanks!

Allotrope
  • 1
  • 1
  • Okay so just checking I'm getting this correct. The error with the "Where-object" occurs if it is stored in a WinRar? Maybe the issue might be due to how the naming of the WinRar works? Maybe for archiving reasons it puts a - instead of a space between words? That would then cause your "Where-object" to fail. I'm just speculating here but try fiddling around with the spaces between words. – The Grand J Sep 07 '20 at 01:57
  • @TheGrandJ Thanks, I checked the file names/paths and they are all using an underscore in place of spaces. The script starts okay, so I think the paths are alright. That command shouldn't care about where it runs, but maybe it does... it's weird, haha. – Allotrope Sep 07 '20 at 02:13

2 Answers2

0

So according to your comment the archive uses underscore in place of spaces. So looking at your code we see this originally

Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | % { Get-ItemProperty $.PsPath } | Where-Object {$.DisplayName -like 'Risk of Rain 2'} | Select InstallLocation -ExpandProperty InstallLocation

Your error occurs when we try to include the Where-object. So I believe the solution to your problem should be to modify your code as such:

Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | % { Get-ItemProperty $_.PsPath } | Where-Object {$_.DisplayName -like 'Risk_of_Rain_2'} | Select InstallLocation -ExpandProperty InstallLocation

Essentially we changed the -like from 'Risk of Rain 2' to 'Risk_of_Rain_2'

I believe this should solve the problem as it is called by the WinRar it probably still uses the underscore name. Since you are checking for a like name that only indicates that it can include any number and type of characters after or before the words in the like string. The like string itself is exact.

The Grand J
  • 348
  • 2
  • 5
  • 14
0

So...WinRAR gives options for the SFX module used. I was using the default Zip.SFX module when I should have been using Zip64.SFX.

The powershell session it opened previously was 32-bit, which gives a different result when reading the installed programs from the registry.

If you have anything 32/64 bit specific in the commands being run after an extraction, make sure the right module is selected in the Advanced SFX options.

Thank you all for the help!

Advanced SFX options

Allotrope
  • 1
  • 1
  • I recommend to read the Microsoft documentations [WOW64 Implementation Details](https://learn.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details), [File System Redirector](https://learn.microsoft.com/en-us/windows/win32/winprog64/file-system-redirector) and [Registry Keys Affected by WOW64](https://learn.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys). Then you should have the knowledge why usage of 32-bit SFX module resulted in execution of 32-bit PowerShell which could not find registry key `Risk of Rain 2` in 32-bit `Uninstall` registry key. – Mofi Sep 07 '20 at 09:08
  • Further I recommend to read the Microsoft documentation about [Application Registration](https://learn.microsoft.com/en-us/windows/win32/shell/app-registration). It could be that the executable of the game `Risk of Rain 2` is registered as application after installation in which case it would be better to use the `App Paths` registry key to get the installation directory which is independent on WOW64 in comparison to uninstall registry key which exists twice, once for 64-bit applications and once for 32-bit applications. – Mofi Sep 07 '20 at 09:13