Skip to content

Instantly share code, notes, and snippets.

@ArtisanByteCrafter
Last active March 22, 2019 15:05
Show Gist options
  • Save ArtisanByteCrafter/91167d5178a13f7c038236a5d7881ca7 to your computer and use it in GitHub Desktop.
Save ArtisanByteCrafter/91167d5178a13f7c038236a5d7881ca7 to your computer and use it in GitHub Desktop.
# Often, a 32-bit binary needs to call a 64bit binary or registry hive.
# Place the following code at the very top of a powershell script to determine if powershell.exe is being invoked as a 32bit process, redirect it to use 64bit, then continue executing whatever follows.
# Relaunch in x64 powershell if not already
if ($PSHOME -like "*syswow64*") {
Write-Output 'Relaunching as x64'
& (Join-Path ($PSHOME -replace 'syswow64', 'sysnative') powershell.exe) `
-File $Script:MyInvocation.MyCommand.Path `
@args
Exit
}
# rest of code goes below here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment