copy item to system32

Hi, I have the following script that works but I don’t want it to copy psexec.exe to C:\Windows\SysWOW64. What’s the best way to get it to actually copy to C:\Windows\System32? Thanks for any help in advance.

$path = test-path "c:\windows\system32\psexec.exe" -ErrorAction SilentlyContinue

if ($path -ne $false)
		{
 write "It's there"
}
else
{
write "It's Not there"
Copy-Item "C:\Program Files\Desktop\APPS\files\psexec.exe" -Destination "c:\windows\system32" -force -Recurse
}

If you use a 32-bit Powershell console it will always copy your files to “C:\Windows\SysWOW64” because the 32-bit console “does not see” the real syste32 directory. You should use the 64-bit console.

I had this exact same problem a couple week ago and found the solution. In order to write to the Systme32 folder from a 32-bit app, you need to use the built-in (somewhat undocumented) alias for System32 which is Sysnative.

See the last paragraph in this MSDN page File System Redirector

So, instead of using C:\Windows\System32 you use C:\Windows\Sysnative.

And running the Powershell script on a 64-bit system with a 64-bit Powershell console wouldn’t have worked? Why do you use a 32-bit Powershell console on a 64-bit system at all?

In my case we have over 4,000 systems and all but about a dozen are 64-bit. The apps I’m working on are written on a 32-bit system which are stored and accessed from a file server.

Hmmm … ok, I think I wouldn’t like to limit myself for only 0.12 % of the clients I have to care about. But if it works for you - great. :smiley:

So the original poster has 2 options - change the environment or change all affected scripts.

Thank you for the responses. Truly appreciate it. I went with C:\Windows\Sysnative which works great. Thanks again.