-7

I am trying to call:

[System.IO.File]::Delete($folder)

from the Powershell ISE (not ISEx86). I am logged in as Domain User that is an Administrator on this machine to which I connect using RDP. I have taken ownership over SysWOW64 folder and granted myself FullControl, for this folder, subfolders and files.

But I still get an "Access Denied" when executing the command above from the Powershell console, which runs under my account "Domain\Administrator".

$xxx =  [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
Write-Host $xxx
$sr =  [Environment]::ExpandEnvironmentVariables("%SystemRoot%")
$sr = Join-Path -Path $sr -ChildPath "\SysWOW64\WindowsPowerShell\v1.0\Modules\"
$folder =  Join-Path -Path $sr -ChildPath "\xxx\Modules"
[System.IO.File]::Delete($folder)

Exception calling "Delete" with "1" argument(s): "Access to the path 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\xxx\Modules' is denied." At C:\Users\Administrator.CONTOSO\Documents\Visual Studio 2015\Projects\xxx.Powershell.Commandlets\xxx.Powershell.Commandlets\install-module.ps1:9 char:1 + [System.IO.File]::Delete($folder) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : UnauthorizedAccessException

How can I get access?

enter image description here

closed as off-topic by HopelessN00b, Wesley, yoonix, Katherine Villyard, Reaces Jun 9 '16 at 5:40

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    Only people who really know what they're doing should be deleting system directories. And before you say it, no, you don't qualify, as you weren't even aware that you were using the directory at the time you were trying to delete it. – HopelessN00b Jun 7 '16 at 21:43
  • 5
    OP is not good with computer. – Wesley Jun 8 '16 at 20:54
  • 1
    Perhaps the on-topic page for this site would be of some interest to you. Helping end users delete directories from their computers isn't even close to what this site is about. – HopelessN00b Jun 8 '16 at 21:23
  • 2
    Pretty sure that's off-topic here too. – yoonix Jun 8 '16 at 22:47
  • 2
    On ServerFault we keep an air of professionalism not found on sites like StackOverflow. – Colyn1337 Jun 8 '16 at 22:51
5

Erm... You can't delete active files like this. You called a 64 bit powershell instance to delete a module for the 64bit shell. Powershell preloads modules (but doesn't necessarily install them) which locks the module file.

  • I don't want to delete a module, the folder is called "Modules" somewhere below SysWOW64... – Legends Jun 7 '16 at 22:31
  • .. It is a folder I created with powershell console and now I want to delete the same empty folder with powershell again. But I get an "Access Denied". – Legends Jun 7 '16 at 22:39
  • You didn't create it, it was there before you tried. It's there with all 64bit installations. – Colyn1337 Jun 8 '16 at 15:47
  • `C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules` is a system leaf on 64bit windows systems for the 64bit Powershell. – Colyn1337 Jun 8 '16 at 21:23
  • That directory is integral to your question and the resolution. – Colyn1337 Jun 8 '16 at 22:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.