Robocopy files without writing permissions / granting temporary writing permission

4

I try to robocopy my "C:\Program Files" directory (and further) to D: drive in audit mode during Windows 10 installation with:
robocopy "C:\Program Files" "D:\Program Files" /E /XJ /COPYALL

However some folders (e.g. C:\Program Files\WindowsApps) are owned by SYSTEM or TrustedInstaller. So, after the directory hierarchy of these are created, writing files is not permitted there and the robocopy task fails and skips it.

Since taking ownership of all these would be an awkward way, I wonder if there's a solution to archive robocopying the Program Files directory.

PS: If someone knows an easier way to relocate Windows Program Data directories to a different drive I'd be very interested.

Reizo

Posted 2017-05-19T16:26:12.183

Reputation: 143

Answers

2

Untested suggestion:

Cmd As SYSTEM

  • Perform the Robocopy from that new command prompt window (so Robocopy runs as the SYSTEM).
  • Delete PSExec before exiting Audit Mode.

Ƭᴇcʜιᴇ007

Posted 2017-05-19T16:26:12.183

Reputation: 103 763

This is perfect, and exactly what I needed. Have a huge thanks! – Reizo – 2017-05-19T17:19:50.113

After all, copying worked perfectly fine using this method. However trying to delete C:\Program Files ended in an 'access denied' error again. Can you figure out a solution for that? – Reizo – 2017-05-20T11:54:34.350

@Reizo You should 1) Mark this answer as accepted based on it solving your problem, and 2) Ask a separate question to address the problem deleting the folder. On the Stack Exchange Q&A sites we generally stick to one question per question. Thanks for participating on SU! – I say Reinstate Monica – 2017-05-20T15:03:26.663

@Twisty I did mark this question as accepted before I commented at the first place :o Concerning the second point I have to admit you're very right. (However I found a solution anyway so for anyone who will read this in future: This tool allows running command line as TrustedInstaller and thus deleting said directory.) Thanks for keeping everything in order.

– Reizo – 2017-05-21T18:38:44.060