0

For example, if i want to empty recycle bin, i use rd /s %systemdrive%\$Recycle.bin in cmd. But it is necessary to run cmd with administrator privileges. Otherwise, access will be denied.

Besides, there is a small command-line tool called Nircmd. It is only 115 kb. For the process I mentioned, i write nircmd emptybin and there is no need to start nircmd with admin privileges.

What is the explanation for a batch command I wrote asking administrator privileges when a third-party tool can do this without any privileges?

Gerhard
  • 22,678
  • 7
  • 27
  • 43
birisix
  • 13
  • 3
  • 1
    Deleting the `$Recycle.bin` directory is not the same action as emptying the Recycle Bin; the former tries to delete a system directory (even the directory itself), the latter triggers an activity provided by the Windows Explorer under the current user context that is not available to the console… – aschipfl May 09 '21 at 13:52
  • 2
    As @aschipfl said, deleting something from `c:\windows\system32` requires admin privileges.. you can however use powershell `Clear-RecycleBin -Force` – Gerhard May 09 '21 at 13:59
  • [How to clear the content of the recycle bin in PowerShell?](https://www.tutorialspoint.com/how-to-clear-the-content-of-the-recycle-bin-in-powershell) – Hackoo May 09 '21 at 14:23
  • The recycle bin should not be emptied by one of your scripts, unless you are positive that **only** files related to your script have been stored there. There's a reason why Windows by default has a holding location for files intended for deletion, too often mistakes are made either deleting accidentally, or by flawed judgement at that time. It should therefore not be your decision, to prevent the end users from fixing such mistakes, later, by removing that built-in safety mechanism. You should only empty the 'bin' as part of a user considered cleanup procedure, is this command one of those? – Compo May 09 '21 at 14:52
  • I didn't ask for a code suggestion. Sorry for causing confusion. I just wondered how nircmd could achieve this. Understood. Thanks for the answers. – birisix May 09 '21 at 15:49
  • 1
    I think the most relevant comment here is by @aschipfl which really answers your question. As demonstrated by the powershell command I posted, it does not require admin privileges to clear the recycle bin but deleting the system file is different from cleaning it and you simply required administrator privileges because you attempted to delete a system file. So hope that sums it up – Gerhard May 09 '21 at 16:03
  • Based upon your [clarification comment](https://stackoverflow.com/questions/67458313/how-does-nircmd-do-some-processes-without-admin-privileges#comment119235856_67458313), your question would be more suited to another site, because you're actually seeking information on the internal processes of a specific compiled software product, as opposed to looking for assistance with an issue with provided code. – Compo May 09 '21 at 17:44

0 Answers0