Need help to create a batch file

Page 1 of 3 123 LastLast

  1. Posts : 155
    Windows 10 Pro
       #1

    Need help to create a batch file


    Hi Folks,

    I need to create a batch file that automatically takes permissions & delete the following file & folders

    File:- C:\Windows\System32\SecurityHealthSystray.exe

    Folders:-

    C:\Windows\WinSxS\amd64_windows-securityhealth-sso_31bf3856ad364e35_10.0.19041.1_none_753cc0191556f0a2

    C:\Windows\WinSxS\amd64_windows-securityhealth-sso_31bf3856ad364e35_10.0.19041.746_none_9d44fd61d4c8aeec

    Can anyone help/guide me on how to create it properly?
      My Computer


  2. Posts : 7,607
    Windows 10 Home 20H2
       #2

    Code:
    TAKEOWN /F "C:\Windows\System32\SecurityHealthSystray.exe" /a
    iCacls "C:\Windows\System32\SecurityHealthSystray.exe" /reset
    DEL /F /Q  "C:\Windows\System32\SecurityHealthSystray.exe"
    
    Set "Folder1=C:\Windows\WinSxS\amd64_windows-securityhealth-sso_31bf3856ad364e35_10.0.19041.1_none_753cc0191556f0a2"
    TAKEOWN /F "%Folder1%" /a /r /d y
    iCacls "%Folder1%" /INHERITANCE:E /GRANT:R "%UserName%":(F) /T /C
    RD /s /q "%Folder1%"
    
    Set "Folder2=C:\Windows\WinSxS\amd64_windows-securityhealth-sso_31bf3856ad364e35_10.0.19041.746_none_9d44fd61d4c8aeec"
    TAKEOWN /F "%Folder2%" /a /r /d y
    iCacls "%Folder2%" /INHERITANCE:E /GRANT:R "%UserName%":(F) /T /C
    RD /s /q "%Folder2%"
    Last edited by Matthew Wai; 17 Mar 2021 at 08:43.
      My Computer


  3. Posts : 6,319
    Windows 11 Pro - Windows 7 HP - Lubuntu
       #3

    Matthew Wai, you're very good with CMDs

    If the folder you want to delete has files and folders, don't you need to clean them first?
      My Computers


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

    Megahertz said:
    If the folder you want to delete has files and folders, don't you need to clean them first?
    No, that's what Mathew used the /S /Q options for.

    Code:
    >RD /?
    Removes (deletes) a directory.
    
    RMDIR [/S] [/Q] [drive:]path
    RD [/S] [/Q] [drive:]path
    
        /S      Removes all directories and files in the specified directory
                in addition to the directory itself.  Used to remove a directory
                tree.
    
        /Q      Quiet mode, do not ask if ok to remove a directory tree with /S
      My Computers


  5. Posts : 6,319
    Windows 11 Pro - Windows 7 HP - Lubuntu
       #5

    Bree said:
    No, that's what Mathew used the /S /Q options for.

    Code:
    >RD /?
    Removes (deletes) a directory.
    
    RMDIR [/S] [/Q] [drive:]path
    RD [/S] [/Q] [drive:]path
    
        /S      Removes all directories and files in the specified directory
                in addition to the directory itself.  Used to remove a directory
                tree.
    
        /Q      Quiet mode, do not ask if ok to remove a directory tree with /S
    Thanks Bree
    I suppose it also work if you have Hidden or system files on it.
      My Computers


  6. Posts : 7,607
    Windows 10 Home 20H2
       #6

    Megahertz said:
    If the folder you want to delete has files and folders, don't you need to clean them first?
    RD /s /q "%Folder%" will delete the folder whether it is empty or not.


    Megahertz said:
    Matthew Wai, you're very good with CMDs
    I am very good at plagiarizing codes from various online sources.
      My Computer


  7. Posts : 1,746
    Windows 10 Pro x64 22H2
       #7

    Megahertz said:
    I suppose it also work if you have Hidden or system files on it.
    I think del command would be more suited for this task, not sure.

    Code:
    del FOLDER /Q /S
    At least this works to remove files that have invalid path characters. (which otherwise can't be removed by normal means)
      My Computer


  8. Posts : 7,607
    Windows 10 Home 20H2
       #8

    zebal said:
    (which otherwise can't be removed by normal means)
    The following script can remove a folder that cannot be removed by normal means.

    Delete Folder in Windows 10
      My Computer


  9. Posts : 14,020
    Win10 Pro and Home, Win11 Pro and Home, Win7, Linux Mint
       #9

    Matthew Wai said:
    RD /s /q "%Folder%" will delete the folder whether it is empty or not.



    I am very good at plagiarizing codes from various online sources.
    I wouldn't call it that, too much like phishing. Like everyone does, it's just taking the short route to the solution, they all exist in documentation somewhere if one digs deep enough. Remember the DOS Commands books of the past? Still have mine.
      My Computers


  10. Posts : 7,607
    Windows 10 Home 20H2
       #10

    Disclaimer: I have not run the code in post #1. Let the OP tell us whether it works.
      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 23:29.
Find Us




Windows 10 Forums