Why does this code work?

Discussion in 'Windows 10' started by Martin McFly, Aug 18, 2020.

Tags:
  1. Martin McFly

    Martin McFly MDL Novice

    Aug 18, 2020
    2
    0
    0
    #1 Martin McFly, Aug 18, 2020
    Last edited by a moderator: Aug 18, 2020
    Just read and used an article titled, "How to Take Ownership and Gain Full Control Permissions in Windows" which contained the below code. My question─which books do I need to read in order for me to understand why this code did what it did, and be able to do similar projects?

    THANKS!
    Marty

    Code:
    [HKEY_CLASSES_ROOT\*\shell\runas] @="Take Ownership"
    "NoWorkingDirectory"=""
    
    [HKEY_CLASSES_ROOT\*\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
    "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
    
    [HKEY_CLASSES_ROOT\Directory\shell\runas] @="Take Ownership"
    "NoWorkingDirectory"=""
    
    [HKEY_CLASSES_ROOT\Directory\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
    "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
    
    [HKEY_CLASSES_ROOT\*\shell\runas] @="Take Ownership"
    "NoWorkingDirectory"=""
    
    [HKEY_CLASSES_ROOT\*\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
    "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
    
    [HKEY_CLASSES_ROOT\Directory\shell\runas] @="Take Ownership"
    "NoWorkingDirectory"=""
    
    [HKEY_CLASSES_ROOT\Directory\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
    "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
    
     
  2. Gharlane00

    Gharlane00 MDL Addicted

    Aug 26, 2009
    838
    302
    30
    You do have to be an Administrator or have an Admin Password for this to work. An Administrator can take ownership. It is not some magic trick that lets a guest own your system.
     
  3. Martin McFly

    Martin McFly MDL Novice

    Aug 18, 2020
    2
    0
    0
    Umm, I know that. That's not the question.
     
  4. 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...
  5. Enthousiast

    Enthousiast MDL Tester

    Oct 30, 2009
    47,247
    94,633
    450
    He asked what each line of code supposed to do, not a redirection to the many useless tools online.
     
  6. kaljukass

    kaljukass MDL Guru

    Nov 26, 2012
    3,396
    1,322
    120
    But why don't you do it then? Answer the question and stop trolling.
    No one forbids you to answer the question and explain.
    And also open your PM.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. case-sensitive

    case-sensitive MDL Expert

    Nov 7, 2013
    1,681
    729
    60
    He asked ---- > ' why this code did what it did ' ...... wich isnt a good question ......because its like asking why the sentaces he wrote mean what they mean .

    That means that untill he clarifys what he wants to know we can only try to understand what he wants and not what he said and explain that .

    If anyone has a better explanation than kaljukass they should please post it
     
  8. Enthousiast

    Enthousiast MDL Tester

    Oct 30, 2009
    47,247
    94,633
    450
    Why would i do that when i only pointed out what the OP wants to know, maybe because of all your posts starting with "i have no clue about the post" and next you post all kinds of nonsense ending with "i have no clue about it".

    Sadly many technical members here don't bother to answer these questions anymore, others should know their limitations.

    My attempt, with my limited knowledge, to explain would be:
    The code creates the rightclick context menu for the code to be ran which elevates privileges/rights/permissions to take over controll/ownership of certain files or folders.
     
  9. case-sensitive

    case-sensitive MDL Expert

    Nov 7, 2013
    1,681
    729
    60
    Marty did you notice that you have the same thing twice in that code box ?

    Code:
    [HKEY_CLASSES_ROOT\*\shell\runas] @="Take Ownership"
    "NoWorkingDirectory"=""
    
    [HKEY_CLASSES_ROOT\*\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
    "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
    
    [HKEY_CLASSES_ROOT\Directory\shell\runas] @="Take Ownership"
    "NoWorkingDirectory"=""
    
    [HKEY_CLASSES_ROOT\Directory\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
    "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
     
  10. kaljukass

    kaljukass MDL Guru

    Nov 26, 2012
    3,396
    1,322
    120
    #11 kaljukass, Aug 19, 2020
    Last edited: Aug 19, 2020

    Attached Files:

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. endbase

    endbase MDL Guru

    Aug 12, 2012
    4,673
    1,708
    150
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...