Search code examples
powershellcmdwindows-10

How do you delete C:\Program Files\SomeApp without administrator privileges?


I am currently attempting to delete the C:\Program Files\SomeApp folder on a test PC where I do not know the administrator password. I have access to cmd.exe, powershell, and not much else.

When I try running rm "C:\Program Files\TestApp\*" I get this:

Confirm
The item at C:\Program Files\TestApp has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you
 sure you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):

When I say y + [ENTER] it says this:

At line:1 char:1
+ rm "C:\Program Files\TestApp\*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (SomeFile.txt:FileInfo) [Remove-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
rm : Cannot remove item C:\Program Files\TestApp\SomeFile.txt: Access to the path 'SomeFile.txt' is denied.

Which was expected, but I was hoping otherwise.

Anyway, Thanks in advance!


Solution

  • With User Account Control enabled (the default and recommended setting), administrator rights are required to modify the C:\Program Files folder.

    https://learn.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-overview

    https://learn.microsoft.com/en-us/windows/win32/dxtecharts/user-account-control-for-game-developers

    https://learn.microsoft.com/en-us/previous-versions/dotnet/articles/bb530410(v=msdn.10)

    https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc709691(v=ws.10)