Request: Two simple scripts to take and restore ownership of folders and files

Discussion in 'Scripting' started by anansay, Nov 16, 2020.

  1. anansay

    anansay MDL Member

    Joined:
    Jul 13, 2020
    Messages:
    112
    Likes Received:
    10
    Trophy Points:
    10
    Currently, when I try to delete a folder, sub-folders and files in C:\Windows\System32\DriverStore, a message will pop up, stating:

    What I do is to manually change the permissions from SYSTEM to the name of the user. Next, I make changes to whatever files that need to be changed. When that is done, I change the permissions back to SYSTEM manually.

    If someone here on MDL has those two scripts, please share them with me. For security reasons, I do not wish to use third party executables.
     
  2. drew84

    drew84 MDL Addicted

    Joined:
    Mar 13, 2014
    Messages:
    956
    Likes Received:
    1,491
    Trophy Points:
    30
  3. anansay

    anansay MDL Member

    Joined:
    Jul 13, 2020
    Messages:
    112
    Likes Received:
    10
    Trophy Points:
    10
  4. kaljukass

    kaljukass MDL Guru

    Joined:
    Nov 26, 2012
    Messages:
    2,436
    Likes Received:
    883
    Trophy Points:
    90
    write these two simple scripts you need, for yourself. These are take ownership and reset permissions.
    In the first case, use the takeown.exe gadget on your computer (located in %windir%\System32\takeown.exe)
    Read about usage here

    Code:
    https://theitbros.com/using-takeown-exe-command-to-take-ownership-of-file-or-folder/
    or use the icacls.exe gadget on your computer
    (location %windir%\System32\icacls.exe)
    Read more about its use here

    Code:
    https://theitbros.com/using-icacls-to-list-folder-permissions-and-manage-files/
    These pages also have examples.
    You will find more ready-made variants
    Code:
    https://www.google.com/search?q=takeown.exe+command&oq=takeown.exe&aqs=chrome.4.69i57j0l3j0i30l4.16783j0j1&sourceid=chrome&ie=UTF-8
    https://www.google.com/search?q=icacls.exe+command+adds&oq=icacls.exe+&aqs=chrome.6.69i57j0i457j0l6.14894j0j1&sourceid=chrome&ie=UTF-8
    
     
  5. anansay

    anansay MDL Member

    Joined:
    Jul 13, 2020
    Messages:
    112
    Likes Received:
    10
    Trophy Points:
    10
    The stuff that you provided looks interesting and I shall have a look at them. Thanks a lot.
     
  6. drew84

    drew84 MDL Addicted

    Joined:
    Mar 13, 2014
    Messages:
    956
    Likes Received:
    1,491
    Trophy Points:
    30
    .. and what do you think that scripts do when they allow you to access protected files? :confused:
     
  7. kaljukass

    kaljukass MDL Guru

    Joined:
    Nov 26, 2012
    Messages:
    2,436
    Likes Received:
    883
    Trophy Points:
    90
    #7 kaljukass, Nov 17, 2020
    Last edited: Nov 17, 2020
    Here is what I have used for years. These are reg files and scripts to add it all to right-click menu. Then it's very simple to use.
    Take Ownership and Reset Permissions reg files and scripts.
    I'm not going to post them here as a script, because that would be a pretty long post then, and I've posted it before.
    So, everything is included in the attached file. Unzip, you get two folders that have everything you need. Ie scripts for a separate file, for a folder, scripts for directory and all together, as well as registry files separately and all together.
    You can use or .reg files or .bat scripts or .vbs scripts - select what You like more.
    (NB Recommended: Run scripts in administrator privileges.)
     

    Attached Files: