[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

    Joined:
    Aug 19, 2009
    Messages:
    254
    Likes Received:
    63
    Trophy Points:
    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

    Joined:
    Dec 9, 2011
    Messages:
    584
    Likes Received:
    255
    Trophy Points:
    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

    Joined:
    Nov 26, 2012
    Messages:
    2,436
    Likes Received:
    883
    Trophy Points:
    90
    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.
     
  4. pf100

    pf100 MDL Expert

    Joined:
    Oct 22, 2010
    Messages:
    1,906
    Likes Received:
    3,055
    Trophy Points:
    60
    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

    Joined:
    Dec 9, 2011
    Messages:
    584
    Likes Received:
    255
    Trophy Points:
    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

    Joined:
    Nov 26, 2012
    Messages:
    2,436
    Likes Received:
    883
    Trophy Points:
    90