Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I run into this issue a lot with my configuration scripts. The basic approach I take is to </p> <ol> <li>Use several functions to test if I'm in a 64 bit environment (<a href="http://blogs.msdn.com/jaredpar/archive/2008/10/16/powershell-and-64-bit-windows-helper-functions.aspx" rel="noreferrer">http://blogs.msdn.com/jaredpar/archive/2008/10/16/powershell-and-64-bit-windows-helper-functions.aspx</a>)</li> <li>Invoke x86/x64 PowerShell based on the needs of a particular script</li> </ol> <p>Unfortunately a lot of this is done in a brute force manner. Each particular configuration entry that is x86/x64 dependent essentially has 2 code paths (one for each architecture). </p> <p>The only real exception I've been able to make is to test for the existince of certain programs on disk. I have a handy function (Get-ProgramFiles32) which makes it easy to test for programs.</p> <pre><code>if ( test-path (join-path Get-ProgramFiles32 "subversion") ) { ... </code></pre> <p>Here are all of the helper functions that I have in my common library that deal with 32/64 bit differences. </p> <pre><code># Get the path where powershell resides. If the caller passes -use32 then # make sure we are returning back a 32 bit version of powershell regardless # of the current machine architecture function Get-PowerShellPath() { param ( [switch]$use32=$false, [string]$version="1.0" ) if ( $use32 -and (test-win64machine) ) { return (join-path $env:windir "syswow64\WindowsPowerShell\v$version\powershell.exe") } return (join-path $env:windir "System32\WindowsPowerShell\v$version\powershell.exe") } # Is this a Win64 machine regardless of whether or not we are currently # running in a 64 bit mode function Test-Win64Machine() { return test-path (join-path $env:WinDir "SysWow64") } # Is this a Wow64 powershell host function Test-Wow64() { return (Test-Win32) -and (test-path env:\PROCESSOR_ARCHITEW6432) } # Is this a 64 bit process function Test-Win64() { return [IntPtr]::size -eq 8 } # Is this a 32 bit process function Test-Win32() { return [IntPtr]::size -eq 4 } function Get-ProgramFiles32() { if (Test-Win64 ) { return ${env:ProgramFiles(x86)} } return $env:ProgramFiles } function Invoke-Admin() { param ( [string]$program = $(throw "Please specify a program" ), [string]$argumentString = "", [switch]$waitForExit ) $psi = new-object "Diagnostics.ProcessStartInfo" $psi.FileName = $program $psi.Arguments = $argumentString $psi.Verb = "runas" $proc = [Diagnostics.Process]::Start($psi) if ( $waitForExit ) { $proc.WaitForExit(); } } # Run the specified script as an administrator function Invoke-ScriptAdmin() { param ( [string]$scriptPath = $(throw "Please specify a script"), [switch]$waitForExit, [switch]$use32=$false ) $argString = "" for ( $i = 0; $i -lt $args.Length; $i++ ) { $argString += $args[$i] if ( ($i + 1) -lt $args.Length ) { $argString += " " } } $p = "-Command &amp; " $p += resolve-path($scriptPath) $p += " $argString" $psPath = Get-PowershellPath -use32:$use32 write-debug ("Running: $psPath $p") Invoke-Admin $psPath $p -waitForExit:$waitForExit } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload