[Question] Delete files with denied access with batch scripts

Page 1 of 2 12 LastLast

  1. DMD
    Posts : 86
    W10 Pro 64 bit 21H1
       #1

    [Question] Delete files with denied access with batch scripts


    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
      My Computer


  2. Posts : 8,111
    windows 10
       #2

    It depends why access is denied is it in use or permission wrong on it?
      My Computer


  3. DMD
    Posts : 86
    W10 Pro 64 bit 21H1
    Thread Starter
       #3

    I am already logged in as an administrator
      My Computer


  4. Posts : 5,330
    Windows 11 Pro 64-bit
       #4

    You need to run the script with administrative privileges.
      My Computer


  5. DMD
    Posts : 86
    W10 Pro 64 bit 21H1
    Thread Starter
       #5

    The script should be inserted in an automatic sequence,
    it is not possible to insert a command to take possession of the file and delete it?
    Thank you
      My Computer


  6. Posts : 31,675
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #6

    DMD said:
    this is the script that gives me "Access denied"....
    del "C: \ SYSTAG.BIN" / A / F / Q / S
    'Access denied' may be because the file is open. Another cause of 'access denied' can be ownership and/or permissions. If it is permissions, try running the script as administrator.

    By the way, you don't put a space between the '/' and the option letter, and the /A option on its own like that does nothing. It is for selecting files by attribute and should be followed by a colon and list of attributes, eg. /A:RSH

    The SYSTAG.BIN file is usually created by Aomei Backupper and that may have the file open.

    ...this file systag.bin is created by Backupper. It is used for distinguishing system partition from others when you boot from the software's bootable medium.

    You can delete it, but they will be recreated again by default when you perform any operations. On the other hand, even you delete it, the system partition can be recognized as normal when you boot from the bootable medium. However, we still suggest that you'd better keep them for future use..
    what is systag.bin? — AOMEI Forum
      My Computers


  7. Posts : 5,330
    Windows 11 Pro 64-bit
       #7

    When deleting file at root of C: partition you will need administrative privileges.
      My Computer


  8. Posts : 456
    Windows 10
       #8

    This should take care of the file:

    1. It closes Aomei

    2. Makes the Admin group take ownership of the file

    3. Grants Admin group full access

    4. deletes the file

    * The script must be run as with administer privileges:

    Code:
    @echo off
    net session 1> Nul 2> Nul 
    If "%errorlevel%"=="2" Echo The script must run with Admin privileges & pause & exit
    for /f %%a in ('wmic process get name ^|find /i "Aomei"') do taskkill /im "%%a" /f
    
    takeown /a /f "c:\SYSTAG.BIN"
    icacls "C:\SYSTAG.BIN" /grant Administrators:F
    del "C:\SYSTAG.BIN" /f /q /a
    echo.
    pause
    [Question] Delete files with denied access with batch scripts Attached Files
      My Computer


  9. Posts : 456
    Windows 10
       #9

    Only now I've seen that you are from Italy. If your Windows is in italian please change "Administrators" to whatever the Admin group is called in your Windows version. Maybe "Amministratori" ?
      My Computer


  10. DMD
    Posts : 86
    W10 Pro 64 bit 21H1
    Thread Starter
       #10

    [QUOTE = ricardobohner; 1686189] Questo dovrebbe prendersi cura del file:

    1. Si chiude Aomei

    2. Rende il gruppo admin Scegli la proprietà del file

    3. gruppo Grants Admin pieno accesso

    4. elimina il file

    * Lo script deve essere eseguito come con i privilegi di Amministrare:

    [code]
    @echo off
    net session 1> Nul 2> Nul
    Se "% errorlevel%" == "2" Echo Lo script deve essere eseguito con i privilegi di amministratore e mettere in pausa e l'uscita
    per / f %% a in (' processo wmic ottenere nome ^ | trovare / i "Aomei" ') fare taskkill / im "%% a" / f

    takeown / a / f "c: \ SYSTAG.BIN"
    icacls "C: \ SYSTAG.BIN" / grant amministratori : F
    del "C: \ SYSTAG.BIN" / f / q / a
    eco.
    pausa
    [/ code] [/ QUOTE]
    I thank you for your concern.
    Even if I run my script, of the first post, as an administrator the file is deleted.
    Instead I ask which script to insert, running it not as an administrator, to delete the file.
    Thank you
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 04:55.
Find Us




Windows 10 Forums