-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

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
Legenda
  • 89
  • 7
  • The account may be a member of the Administrators group and have FullControl over it, but did you actually choose "Run as Administrator..." when launching ISE? – Mathias R. Jessen Jun 06 '16 at 16:29
  • Yes, I am Administrator. It's indicated in the console title bar. – Legenda Jun 06 '16 at 16:52
  • Is there a tool that i can run which spits out the necessary information about access rights for this folder. I could post the information here then... – Legenda Jun 06 '16 at 17:09
  • 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 07 '16 at 21:43
  • 5
    OP is not good with computer. – Wesley Jun 08 '16 at 20:54
  • 1
    Perhaps the [on-topic page for this site](http://serverfault.com/help/on-topic) 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 08 '16 at 21:23
  • 2
    Pretty sure that's off-topic here too. –  Jun 08 '16 at 22:47
  • yes this is off-topic :-) – Legenda Jun 08 '16 at 22:48
  • but deleting normal user comments is off topic too, the one above can be deleted, but why does a mod delete a normal user comment? – Legenda Jun 08 '16 at 22:49
  • 2
    On ServerFault we keep an air of professionalism not found on sites like StackOverflow. – Colyn1337 Jun 08 '16 at 22:51
  • I had a simple question. So if Serverfault is not the right place for this question I would have appreciated a hint to post it in another forum. Giving wrong answers is not professional in my opinion ;-) Better say, this is the wrong place for that kind of questions instead of deleting not offending user comments... – Legenda Jun 08 '16 at 22:58
  • Hopeless to explain it to @HopelessN00b :D – Legenda Jun 08 '16 at 23:00
  • I'll give up, have a nice evening @HopelessN00b. Goodbye Serverfault – Legenda Jun 08 '16 at 23:07

1 Answers1

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.

Colyn1337
  • 2,397
  • 2
  • 23
  • 40
  • I don't want to delete a module, the folder is called "Modules" somewhere below SysWOW64... – Legenda Jun 07 '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". – Legenda Jun 07 '16 at 22:39
  • You didn't create it, it was there before you tried. It's there with all 64bit installations. – Colyn1337 Jun 08 '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 08 '16 at 21:23
  • That directory is integral to your question and the resolution. – Colyn1337 Jun 08 '16 at 22:44
  • $sr = [Environment]::ExpandEnvironmentVariables("%SystemRoot%") $sr = Join-Path -Path $sr -ChildPath "\SysWOW64\WindowsPowerShell\v1.0\Modules\" $folder = Join-Path -Path $sr -ChildPath "\xxx\Modules" It's the Modules folder under xxx folder... – Legenda Jun 08 '16 at 22:45
  • SysWOW64\WindowsPowerShell\v1.0\Modules is a system folder but I created subfolders xxx\Modules... Do you get it? I dont want to delete the `SysWOW64\WindowsPowerShell\v1.0\Modules` folder – Legenda Jun 08 '16 at 22:46