Get list of files from SYSWOW64 from 64 bit process

565 views Asked by At

I faced with problem during writing of powershell script. I should copy 3 .dll file to C:\Windows\SYSWOW64 folder from poweshell 64-bit process. If I use environment variable

$systemFolder = [System.Environment]::SystemDirectory

So, under 64-bit process on 64 bit system

$systemFolder = "C:\Windows\system32"

Is any enviroment variable or some construction to get access to SYSWOW64 folder. I came up with such solution, but I think there is more correct solution

$targetFolder = [System.Environment]::SystemDirectory
if([Environment]::Is64BitProcess){
$targetFolder = "$env:windir\SYSWOW64"
}

Many thanks

1

There are 1 answers

0
David Martin On BEST ANSWER

I don't see a problem with that solution, but another option for you might be to run your script in a 32bit proccess, you can do this by runnning as a job using Start-Job and the RunAs32 parameter.

Start-Job -ScriptBlock {[Environment]::Is64BitProcess} -RunAs32 | Wait-Job | Receive-Job
False

Start-Job -ScriptBlock {[Environment]::Is64BitProcess} | Wait-Job | Receive-Job
True

Another option is to use Environment.SpecialFolder

[Environment]::GetFolderPath([System.Environment+SpecialFolder]::SystemX86)
C:\WINDOWS\SysWOW64