copy item to system32

Welcome Forums General PowerShell Q&A copy item to system32

This topic contains 6 replies, has 3 voices, and was last updated by

 
Participant
8 months, 3 weeks ago.

  • Author
    Posts
  • #94683

    Participant
    Points: 0
    Rank: Member

    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
    }
  • #94698

    Participant
    Points: 154
    Helping Hand
    Rank: Participant

    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.

  • #94702

    Participant
    Points: 0
    Rank: Member

    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.

    • #94708

      Participant
      Points: 154
      Helping Hand
      Rank: Participant

      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?

  • #94710

    Participant
    Points: 0
    Rank: Member

    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.

  • #94716

    Participant
    Points: 154
    Helping Hand
    Rank: Participant

    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. 😀

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

  • #94879

    Participant
    Points: 0
    Rank: Member

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

The topic ‘copy item to system32’ is closed to new replies.