2

I have a script that runs in WinPE that takes a system drive with Windows installed and deletes everything off of the drive (keeping the filesystem intact).

When dealing with a Windows XP/Vista/7 installation it functions properly. attrib -S -A -H -I -R /S /D \ is run, and then everything is deleted.

However, within Windows 8, I run into an "Access Denied" error. For some reason, even as the SYSTEM user within WinPE, I can't edit the directory C:\ProgramData\Microsoft\Windows\LocationProvider. I can't use attrib to set attributes, I can't delete it - I can't even cd into it! dir /a just returns File Not Found.

Using rmdir /S /Q gives me the "Access Denied" error.

Alyssa Haroldsen
  • 3,652
  • 1
  • 20
  • 35
  • Have you seen this on multiple systems, or just on one particular one? In the latter case, there might be file system corruption. In the former case it's probably a permissions issue, have you checked the ACL set on that directory? – Harry Johnston Jan 29 '13 at 23:51
  • Ah, to be honest, I am not sure how to check the ACL on the command line (this is WinPE, so there's cmd.exe only). This is apparent on every Windows 8 system I've dealt with - it's actually a software bug that I'm trying to fix (proprietary, can't show the code). – Alyssa Haroldsen Jan 30 '13 at 00:02
  • You could probably just check the permissions on that directory on a working system; they are unlikely different when the OS is shut down than when it is running. But the command-line tool for checking permissions is `icacls.exe`; it isn't included in WinPE by default, IIRC, so you'll need to explicitly add a copy to your image, or put one on external media or a network share, or whatever. – Harry Johnston Jan 30 '13 at 00:13
  • You are correct, icacls.exe is not included in WinPE. That's the thing - it has to work with the current files, without a network connection, and without having any previous knowledge of the system. The only thing I can change is the program that runs and deletes the program. Any Win32API calls for ACL you'd recommend for ease of use? – Alyssa Haroldsen Jan 30 '13 at 05:02
  • The first step is to use icacls.exe on a single system to discover whether or not the permissions really are the problem. If they are, it's not all that hard to deal with; it might just be a matter of enabling restore privilege. But it may be that something else is going on. – Harry Johnston Jan 30 '13 at 05:14

2 Answers2

3

Assuming that the problem is related to permissions and/or ownership, you can work around it using the built-in robocopy tool - luckily, this is included in Windows PE.

First, create an empty directory, e.g., x:\empty and then run

robocopy /e /purge /b x:\empty c:\

The /b flag tells robocopy to use backup mode, which bypasses security.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
0

Had the same problem. You need to take ownership first, for example using takeown.exe. Then fix permissions, for example using icacls.exe. Then proceed as you wish with copy, move, delete.

Lumi
  • 14,775
  • 8
  • 59
  • 92