1

I want to deny permission to mentioned folder for current user to access,modify,read. Using icacls. icacls C:\Users\%username%\AppData\Local\Mozilla\updates /q /c /t /deny users:F But i am getting error "The system cannot find the path specified"

Can anyone help me in this regards.

  • The user probably will still be able to delete the file since delete-child access is probably granted by the parent folder. – Eryk Sun Apr 30 '17 at 08:41

1 Answers1

2

Since you didn't provide much information, so my answer will be a guess.

"The system cannot find the path specified"

It obviously means the path does not exist. However, there is one exception: paths with space. To let cmd and batch file properly handle space, you will need to "quote" them. And, as @Mofi mentioned that it could be that the user's profile directory is not C:\Users\%USERNAME%

So my best guess to fix both problems, you should change the command to:

icacls "C:\Users\%Username%\AppData\Local\Mozilla\updates" /q /c /t /deny users:F

or this better solution suggest by @Mofi:

icacls "%LOCALAPPDATA%\Mozilla\updates" /q /c /t /deny users:F
  • The missing double quotes are most likely the reason in case of user name contains command line critical characters like a space character or an ampersand. Another one could be that the user's profile directory is not `C:\Users\%USERNAME%`. So it is better to use `icacls "%USERPROFILE%\AppData\Local\Mozilla\updates" /q /c /t /deny users:F` or best `icacls "%LOCALAPPDATA%\Mozilla\updates" /q /c /t /deny users:F`. See Wikipedia chapter about [Windows Environment Variables](https://en.wikipedia.org/wiki/Environment_variable#Windows). – Mofi Apr 30 '17 at 07:35
  • Except for built-in commands such as `dir`, cmd doesn't care about the spaces in the argument to the command. It's not a POSIX shell that splits the command line into an `argv` array. Every Windows program has to do its own command-line parsing, for which VC++ `argv` rules are typical. That said, quotes also escape other special characters in the shell, such as `&` -- but not `%` on the command-line. Percent can only be escaped reliably in batch files, where doubling it as `%%` does the trick. – Eryk Sun Apr 30 '17 at 08:52
  • @eryksun If you don't quote the parameters together, the exe will see this: `C:\Users\Spaced -arg1` / `Username\blah -arg2` / `/q -arg3...` Which is wrong –  Apr 30 '17 at 09:47
  • Yes, but that has nothing to do with the cmd shell. The executable is responsible for parsing its own command line. – Eryk Sun Apr 30 '17 at 09:51
  • `ICACLS name [/grant[:r] Sid:perm[...]]` `[/deny Sid:perm [...]]` `[/remove[:g|:d]] Sid[...]] [/T] [/C] [/L] [/Q]` `[/setintegritylevel Level:policy[...]]` the `name` is one parameter, not mutliple. –  Apr 30 '17 at 09:54
  • cmd passes the quotes in the command line. When the program starts up it has to parse its command line into arguments. Usually programs rely on the VC++ runtime to parse the command line as the `argv` array of `main` or `wmain`, but programs can call `GetCommandLineW` and use whatever rules they want, or call the shell32 function `CommandLineToArgvW` to use the common rules. – Eryk Sun Apr 30 '17 at 10:01
  • I don't really care how to application(or the program) parses its command line arguments, but cmd **doesn't** automatically quote up your path... –  Apr 30 '17 at 10:03
  • cmd doesn't care about the command's arguments. It doesn't look beyond parsing it for the executable and non-escaped special characters such as `%`, `&`, `|`, `>` that control how it dices the command line up into separate commands. What cares about the quotes here is icacls.exe because it's using standard VC++ rules. But a program can do whatever it wants here. It could require paths with spaces to be quoted using backticks or brackets. That would just be being weird for its own sake, but it's possible. – Eryk Sun Apr 30 '17 at 10:10
  • Try this: `mkdir "spaced dir"`, then `icacls spaced dir ....`. You'll get a syntax error –  Apr 30 '17 at 10:11
  • You mean "invalid parameter". That's printed by `icacls`, not the shell. – Eryk Sun Apr 30 '17 at 10:13
  • And `icacls` doesn't understand `spaced dir` as one string, but it understands `"Space dir"` as one string –  Apr 30 '17 at 10:15
  • icacls.exe uses the `wmain` entry point, for which the rules are described in [Parsing C++ Command-Line Arguments](https://msdn.microsoft.com/en-us/library/17w5ykft.aspx). – Eryk Sun Apr 30 '17 at 10:18
  • Ok. Let me take a look into it, I'll reply you later. –  Apr 30 '17 at 10:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143008/discussion-between-stevefest-and-eryksun). –  Apr 30 '17 at 10:20