Modify this .reg to take ownership of just the drive?


  1. Posts : 740
    Windows 10 x64 Pro
       #1

    Modify this .reg to take ownership of just the drive?


    So im trying to polish off a big ole fancy context menu and I want to add the ability to take ownership of a drive (non system ofc)

    the conventional

    Code:
    @="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c takeown /f \\\"%1\\\" /r /d y && icacls \\\"%1\\\" /grant *S-1-3-4:F /t /c /l /q & pause' -Verb runAs\""
    "IsolatedCommand"="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c takeown /f \\\"%1\\\" /r /d y && icacls \\\"%1\\\" /grant *S-1-3-4:F /t /c /l /q & pause' -Verb runAs\""

    acts recursively and will begin to murder everything beneath it.

    I'd like to make it tantamount to

    Code:
    @="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Administrators\" /c' -Verb runAs\""
    "IsolatedCommand"="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%1\\\" /setowner \"Administrators\" /c' -Verb runAs\""

    but for taking ownership. I dont know if its as simple as using

    Code:
    @="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c takeown /f \\\"%1\\\" && icacls \\\"%1\\\" /grant *S-1-3-4:F /t /c /l & pause' -Verb runAs\""
    "IsolatedCommand"= "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c takeown /f \\\"%1\\\" && icacls \\\"%1\\\" /grant *S-1-3-4:F /t /c /l & pause' -Verb runAs\""

    instead. Or if the /t and /l switch need to be removed as well. Given the sensitivity, I'd prefer defer to the professionals :)
      My Computer


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

    Code:
    :: Add Change Owner to Context Menu in Windows 10
    
    @Echo Off
    
    
    (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)
    
    Cls & Mode CON  LINES=11 COLS=60 & Color 0E & Title Created By FreeBooter
    Echo.
    Echo.
    Echo.
    Echo.       
    Echo         Add "Change Owner" to Context Menu (A)?    
    Echo.       
    Echo         Remove "Change Owner" from Context Menu (R)?
    Echo.
    
    
    Set /p input= RESPONSE: 
    
    If /i  Not %input%==A (Goto :_Ex) Else (Goto :_Add) 
    
    :_Ex
    If /i Not %input%==R  (Goto :EOF) Else (Goto :_Remove)
    
    
    
    :_Add
    
    e add "HKCR\*\shell\ChangeOwner" /v "MUIVerb" /t REG_SZ /d "Change Owner" /f
    Reg.exe delete "HKCR\*\shell\ChangeOwner" /v "Extended" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner" /v "SubCommands" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\01Owner" /ve /t REG_SZ /d "See Current Owner" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\01Owner" /v "Icon" /t REG_SZ /d "imageres.dll,-1029" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\01Owner\command" /ve /t REG_SZ /d "powershell -NoExit Get-ACL '%%1'| Format-List -Property Owner" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Administrators" /ve /t REG_SZ /d "Change Owner to Administrators" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Administrators" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Administrators" /v "CommandFlags" /t REG_DWORD /d "32" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Administrators\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"Administrators\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Administrators\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"Administrators\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Everyone" /ve /t REG_SZ /d "Change Owner to Everyone" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Everyone" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Everyone\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"Everyone\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\Everyone\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"Everyone\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\SYSTEM" /ve /t REG_SZ /d "Change Owner to SYSTEM" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\SYSTEM" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\SYSTEM\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"SYSTEM\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\SYSTEM\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"SYSTEM\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\TrustedInstaller" /ve /t REG_SZ /d "Change Owner to TrustedInstaller" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\TrustedInstaller" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\TrustedInstaller\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"\"\"NT Service\TrustedInstaller\"\"\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\*\shell\ChangeOwner\shell\TrustedInstaller\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"\"\"NT Service\TrustedInstaller\"\"\" /t /c /l' -Verb runAs\"" /f
    REM ; For folders
    Reg.exe add "HKCR\Directory\shell\ChangeOwner" /v "MUIVerb" /t REG_SZ /d "Change Owner" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner" /v "AppliesTo" /t REG_SZ /d "NOT (System.ItemPathDisplay:=\"C:\Users\" OR System.ItemPathDisplay:=\"C:\ProgramData\" OR System.ItemPathDisplay:=\"C:\Windows\" OR System.ItemPathDisplay:=\"C:\Windows\System32\" OR System.ItemPathDisplay:=\"C:\Program Files\" OR System.ItemPathDisplay:=\"C:\Program Files (x86)\")" /f
    Reg.exe delete "HKCR\Directory\shell\ChangeOwner" /v "Extended" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner" /v "NoWorkingDirectory" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner" /v "Position" /t REG_SZ /d "middle" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner" /v "SubCommands" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\01Owner" /ve /t REG_SZ /d "See Current Owner" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\01Owner" /v "Icon" /t REG_SZ /d "imageres.dll,-1029" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\01Owner\command" /ve /t REG_SZ /d "powershell -NoExit Get-ACL '%%1'| Format-List -Property Owner" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Administrators" /ve /t REG_SZ /d "Change Owner to Administrators" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Administrators" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Administrators" /v "CommandFlags" /t REG_DWORD /d "32" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Administrators\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"Administrators\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Administrators\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"Administrators\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Everyone" /ve /t REG_SZ /d "Change Owner to Everyone" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Everyone" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Everyone\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"Everyone\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\Everyone\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"Everyone\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\SYSTEM" /ve /t REG_SZ /d "Change Owner to SYSTEM" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\SYSTEM" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\SYSTEM\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"SYSTEM\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\SYSTEM\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"SYSTEM\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\TrustedInstaller" /ve /t REG_SZ /d "Change Owner to TrustedInstaller" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\TrustedInstaller" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\TrustedInstaller\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"\"\"NT Service\TrustedInstaller\"\"\" /t /c /l' -Verb runAs\"" /f
    Reg.exe add "HKCR\Directory\shell\ChangeOwner\shell\TrustedInstaller\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%%1\\\" /setowner \"\"\"NT Service\TrustedInstaller\"\"\" /t /c /l' -Verb runAs\"" /f
    REM ; For drives
    Reg.exe add "HKCR\Drive\shell\ChangeOwner" /v "MUIVerb" /t REG_SZ /d "Change Owner" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner" /v "AppliesTo" /t REG_SZ /d "NOT (System.ItemPathDisplay:=\"C:\\\")" /f
    Reg.exe delete "HKCR\Drive\shell\ChangeOwner" /v "Extended" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner" /v "NoWorkingDirectory" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner" /v "Position" /t REG_SZ /d "middle" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner" /v "SubCommands" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\01Owner" /ve /t REG_SZ /d "See Current Owner" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\01Owner" /v "Icon" /t REG_SZ /d "imageres.dll,-1029" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\01Owner\command" /ve /t REG_SZ /d "powershell -NoExit Get-ACL '%%1'| Format-List -Property Owner" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Administrators" /ve /t REG_SZ /d "Change Owner to Administrators" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Administrators" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Administrators" /v "CommandFlags" /t REG_DWORD /d "32" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Administrators\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%%1\\\" /setowner \"Administrators\" /c' -Verb runAs\"" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Administrators\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%%1\\\" /setowner \"Administrators\" /c' -Verb runAs\"" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Everyone" /ve /t REG_SZ /d "Change Owner to Everyone" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Everyone" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Everyone\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/k icacls \"%%1\\\" /setowner \"Everyone\" /c' -Verb runAs\"" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\Everyone\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/k icacls \"%%1\\\" /setowner \"Everyone\" /c' -Verb runAs\"" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\SYSTEM" /ve /t REG_SZ /d "Change Owner to SYSTEM" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\SYSTEM" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\SYSTEM\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%%1\\\" /setowner \"SYSTEM\" /c' -Verb runAs\"" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\SYSTEM\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%%1\\\" /setowner \"SYSTEM\" /c' -Verb runAs\"" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\TrustedInstaller" /ve /t REG_SZ /d "Change Owner to TrustedInstaller" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\TrustedInstaller" /v "HasLUAShield" /t REG_SZ /d "" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\TrustedInstaller\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%%1\\\" /setowner \"\"\"NT Service\TrustedInstaller\"\"\" /c' -Verb runAs\"" /f
    Reg.exe add "HKCR\Drive\shell\ChangeOwner\shell\TrustedInstaller\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%%1\\\" /setowner \"\"\"NT Service\TrustedInstaller\"\"\" /c' -Verb runAs\"" /f
    
    
    Cls & Mode CON  LINES=11 COLS=60 & Color 0E & Title Created By FreeBooter
    Echo.
    Echo.
    Echo.
    Echo.       
    Echo          Adding "Change Owner" to Context Menu   
    Echo.       
    Echo.
    Echo. 
    
    
    ping -n 6 localhost >Nul 
    Exit
    
    
    :_Remove
    
    REM ; For files
    Reg.exe delete "HKCR\*\shell\ChangeOwner" /f
    REM ; For folders
    Reg.exe delete "HKCR\Directory\shell\ChangeOwner" /f
    REM ; For drives
    Reg.exe delete "HKCR\Drive\shell\ChangeOwner" /f
    
    
    
    Cls & Mode CON  LINES=11 COLS=60 & Color 0E & Title Created By FreeBooter
    Echo.
    Echo.
    Echo.
    Echo.       
    Echo         Removing "Change Owner" from Context Menu    
    Echo.       
    Echo.
    Echo. 
    
    
    ping -n 6 localhost >nul 
    Exit
      My Computer


  3. Posts : 989
    Microsoft Windows 10 Home
       #3

    All you want is a context menu entry to take ownership without recursion?
    And grant yourself full contril as well?

    Is there any good reason not to do this all in PowerShell as opposed to calling cmd from PowerShell? ( aside from the fact that many stick with batch/cmd out of habit )
      My Computer


  4. Posts : 740
    Windows 10 x64 Pro
    Thread Starter
       #4

    KeithM said:
    All you want is a context menu entry to take ownership without recursion?
    And grant yourself full contril as well?

    Is there any good reason not to do this all in PowerShell as opposed to calling cmd from PowerShell? ( aside from the fact that many stick with batch/cmd out of habit )
    yea i want the context menu due to it being the last piece of a "suite" or "flyout" style context menu that handles ownership commands in their entirety (at least for my use case) with files, folders, and drives. I'd hate to have to turn to another medium for that 1 command.
      My Computer


  5. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #5

    Hello @klepp0906,

    Have you looked at this? => Add Take Ownership to Context Menu in Windows 10.

    I hope this helps!
      My Computer


  6. Posts : 740
    Windows 10 x64 Pro
    Thread Starter
       #6

    Paul Black said:
    Hello @klepp0906,

    Have you looked at this? => Add Take Ownership to Context Menu in Windows 10.

    I hope this helps!
    yes, unfortunately that will take ownership of everything :) an easy way to get in trouble with a brain fart, lapse of judgement, or mis-click lol. thanks though :P
      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 03:21.
Find Us




Windows 10 Forums