[Question] Delete files with denied access with batch scripts

Discussion in 'Windows 10' started by MIMMO61, Aug 4, 2019.

  1. MIMMO61

    MIMMO61 MDL Senior Member

    Aug 19, 2009
    356
    106
    10
    Hi, after years I started working with batch scripts again, but I can't delete a file under the main "C" directory, (using W10 last release), this is the script that gives me "Access denied".

    -----------------------------------------------
    @echo off
    cls
    del "C: \ SYSTAG.BIN" / A / F / Q / S
    exit
    --------------------------------------------------

    What command should I add, if it is possible to do so?
    Thank you
     
  2. whitestar_999

    whitestar_999 MDL Addicted

    Dec 9, 2011
    713
    318
    30
    It seems to be related to aomei backupper & I think this file should be automatically deleted after uninstalling that software.
     
  3. kaljukass

    kaljukass MDL Guru

    Nov 26, 2012
    3,396
    1,322
    120
    No matter what command, but all commands should be written correctly. Even one wrong thing is too much. In your example is too many incorrectly.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,069
    3,449
    90
    You've got extra spaces where there shouldn't be. /A should specify a file attribute(s) (/A:S) in a del command but isn't needed here anyway, and /S isn't needed because a file can't have a subdirectory. The filename doesn't need to be in quotes since there are no spaces. I don't know if you need to take ownership of the file or not but it won't hurt anything. Run this as administrator.

    Code:
    -----------------------------------------------
    @echo off
    cls
    takeown /f C:\SYSTAG.BIN /a
    del C:\SYSTAG.BIN /F /Q
    exit
    --------------------------------------------------
    
     
  5. whitestar_999

    whitestar_999 MDL Addicted

    Dec 9, 2011
    713
    318
    30
    @kaljukass @pf100 This file seems to be related to Aomei backupper so I am not sure deleting this file without clearing the situation first is a good idea.Also if this file is being protected by some aomei service/driver(with system privilege) running in background then which type of cmd command can delete it anyway.
     
  6. kaljukass

    kaljukass MDL Guru

    Nov 26, 2012
    3,396
    1,322
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...