0

The question is probably best explained with the scenario, where I realized the two programs are operating differently.

I had an old backup from my Linux days on my hard drive containing a file named con. As MSDN states, con is a reserved device name and may not be used for files:

Do not use the following reserved device names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9

So I had problems deleting the file, but with proper name escaping as I found it in this command from a Super User answer, I was able to delete it:

del "\\.\F:\Movies\Con Man\Con.Man.2018.720p.WEBRip.x264-[YTS.AM].mp4"

First, I tried to delete the file with the given command via PowerShell. It threw an error saying the directory or drive does not exist. Only C:\WINDOWS\System32\cmd.exe was able to delete the file. I ran both shells with administrator permissions.

So from this point I simply wanted to know: Why do they behave differently? Is there some sort of sepearate permission level for PowerShell or is it running in some sort of special sandbox?

narranoid
  • 13
  • 5
  • 1
    Hold on – the file in your example isn't actually named `con`, is it? – u1686_grawity Sep 21 '18 at 09:44
  • @grawity Yes it was. The command I cited was not specifically for a file named just con, but I used it for a file named con (and only con) and it worked via cmd.exe. I think it was some auto generated file which happened to appear during my software developer days on Linux. I don't now how it appeared specifically. – narranoid Sep 21 '18 at 10:21

1 Answers1

0

Neither.

Command Prompt is a continuation from old MS-DOS where the only way to communicate with special devices was to use their device names: PRN, CON, Etc...

This basically means that a file that is called by a device, followed by a period is illegal in windows. MS-DOS has a workaround for it, but Powershell doesn't. This basically means you cannot work with a file that violated this illegal filename in windows.

So yes, they are very different for that reason. Not just in what they can do, but the entire syntax is different. Powershell can be used to do things that Command Prompt can, but not the other way around.

LPChip
  • 59,229
  • 10
  • 98
  • 140
  • I am aware of the extra power of PowerShell, but in my case I used a command available for both and PowerShell still had troubles with it. First I tried Remove-Item from PowerShell as well, but it threw an access number error. – narranoid Sep 21 '18 at 10:24
  • And I tried to explain that the path itself is special and because powershell can access the file normally, the special access path does not need to be used, nor does it work. – LPChip Sep 21 '18 at 10:27
  • But I started to research the special access path syntax after I tried to delete it with regular path syntax. And that didn't work in PowerShell either. – narranoid Sep 21 '18 at 10:41
  • did some more testing, and it seems indeed that powershell can't get to the file. Powershell does not understand alternative streams such as \\.\ so it won't work through that either. But you asked, are they different, yes they are. But I'll edit my answer to rectify the mistake I made. – LPChip Sep 21 '18 at 11:58
  • Wow, thanks for the effort! That's a pretty decent answer to my question now. – narranoid Sep 22 '18 at 15:45