batch file code delete stubborn file ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mysystem
Posts: 9
Joined: 25 Oct 2021 07:00

batch file code delete stubborn file ?

#1 Post by Mysystem » 09 Apr 2022 04:06

hi
batch file code delete stubborn file ?

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: batch file code delete stubborn file ?

#2 Post by ShadowThief » 09 Apr 2022 07:19

Probably some combination of the TAKEOWN and ICACLS commands, but there's probably a very good reason why you aren't able to delete that file.

Jedininja
Posts: 25
Joined: 11 Jan 2022 22:41
Location: CanafukpilesDa
Contact:

Re: batch file code delete stubborn file ?

#3 Post by Jedininja » 11 Apr 2022 02:03

I have done extensive testing on how to delete stubborn files and i have a few solutions.

A)
Edit group policy to allow the user about to delete files admirative permissions.
- open gpedit.exe
- goto Local Computer Policy / Computer Configuration / Windows Settings / Security Settings / User Rights Assignment / Take ownership of files or other objects
note: lots of usefully settings in gpedit.exe however you can very easily break your OS install this also applies to User Account Permission's and Ownership/Inherence

B)
Change the User Account Permission's and Ownership
- Open Security and Maintenance in Control Panel/System and Security.
OR
- "Security" Tab in the left click file properties menu

- Set user permissions and ownership to :
Allow Administrators
Allow Users
Allow Everyone
Remove all the other user permission's
Disable File Inheritance
this will insure that whatever account your using can access it the file or folder.
than you can
- RD /F
- Del /F
- Shift Delete in the UI
C)
- boot any windows media in boot mode,
- get to a cmd window and
- manually delete the file with del or rd
- type notepad into the cmd window
goto "open file"
Select "all file types"
search for the file you want to delete
note: this will also work with an offline Linux live boot os/ or as alongside Linux install


Hope is Helpful

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: batch file code delete stubborn file ?

#4 Post by jfl » 13 Apr 2022 07:28

What do you mean by stubborn file?

Before going through complex and risky procedures like updating group policies, it'd be easier if we knew more about what you did, and what error messages you got.

The most common cases are
- A read-only file
- A file for which you don't have the necessary user rights
- Did you try doing this in an Administrator command shell?
- Some files are owned by the Windows system. Deleting them is usually a very bad idea. If you know for sure it's safe to delete it, MS SysInternals has tools for running a command as system.
- Maybe the file has a name incompatible with standard WIN32 APIs? (Like ending with a space, or called "nul", etc. This can happen when using the WSL.)
In which case prefixing the full pathname with \\?\ usually resolves the issue.

Post Reply