2

I want my 7-zip self-extracting archive to run a PowerShell script after it extracts files. To do that, I use method described here: http://www.sphaero.org/blog:2011:0504_7zip_self_extracting_autostart_exe

After file extraction I want to run a powershell script, so here is my config.txt file contents:

;!@Install@!UTF-8!
RunProgram="InstallCU.bat"
;!@InstallEnd@!

The InstallCU.bat file launches PowerShell:

powershell.exe -ExecutionPolicy Unrestricted -File InstallCU.ps1

Inside the powershell script I do many things, including checking some registry keys under this branch:

HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components

using Test-Path and Get-ItemProperty cmd-lets

I didn't test it out, but I think on 32-bit computers everything will run fine.

My problem is that on 64-bit systems, 32-bit (x86) version of the PowerShell launches. When I access any path in registry under HKLM:\Software in it, it is being redirected to HKLM:\Software\Wow6432Node\ and, of course, fails to find the information I need (because it is in the 64-bit registry branch)

Question:

1) How do I make 64-bit 7-zip SFX?

OR

2) How do I run 64-bit PowerShell from 32-bit SFX?

OR

3) How do I read 64-bit registry (not Wow6432Node) via 32-bit powershell? (Though I think that's either impossible or will greatly increase the amount of PowerShell code)

OR

Any other suggestions?

2 Answers 2

1

Here is a nested Archetype function for determining OS bitness + Powershell bitness. Added sysnative path in a variable to reg.exe so you can reg edit the x64 keys from a 32bit process. If you don't prefer reg.exe, I'm sure there are other ways to do the same trick.

    Function ARCHETYPE (){

    $ARCH = (Get-WmiObject -class Win32_OperatingSystem | Select-Object OSArchitecture).OSArchitecture
    If ($ARCH -eq '64-bit') {
    $DOUBLEARCHES = (Get-Process -Id $PID).StartInfo.EnvironmentVariables["PROCESSOR_ARCHITECTURE"]
    If ($DOUBLEARCHES -eq 'x86') {
    Write-Host 'Running 32-bit PowerShell on 64-bit Windows'
    $REG = "%WINDIR%\sysnative\reg.exe"
    }
    ElseIf ($DOUBLEARCHES -eq 'amd64') {
    Write-Host 'Running 64-bit PowerShell on 64-bit Windows'
    $REG = "%WINDIR%\system32\reg.exe"
    }
    }Else{
    Write-Host 'Running 32-bit PowerShell on 32-bit Windows'
    $REG = "%WINDIR%\system32\reg.exe"
    }
    Write-Host "$REG"
    }

    ARCHETYPE

Result

Running 64-bit PowerShell on 64-bit Windows
%WINDIR%\system32\reg.exe

or

Running 32-bit PowerShell on 64-bit Windows
%WINDIR%\sysnative\reg.exe
1

Probably to late but it's worth to let anybody else know, there is a module "7zsd_All_x64.sfx" add it to your config file and archive and you will have a 64 bit

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .