8

As part of a build setup on a windows machine I need to add a registry entry and I'd like to do it from a simple batch file.

The entry is for a third party app so the format is fixed.

The entry takes the form of a REG_SZ string but needs to contain newlines ie. 0xOA characters as separators.

I've hit a few problems.

First attempt used regedit to load a generated .reg file. This failed as it did not seem to like either either long strings or strings with newlines. I discovered that export works fine import fails. I was able to test export as the third party app adds similar entries directly through the win32 api.

Second attempt used the command REG ADD but I can't find anyway to add the newline characters everything I try just ends up with a literal string being added.

5 Answers 5

5

You can import multiline REG_SZ strings containing carriage return (CR) and linefeed (LF) end-of-line (EOL) breaks into the registry using .reg files as long as you do not mind translating the text as UTF-16LE hexadecimal encoded data. To import a REG_SZ with this text:

1st Line
2nd Line

You might create a file called MULTILINETEXT.REG that contains this:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Environment]
"MULTILINETEXT"=hex(1):31,00,73,00,74,00,20,00,4c,00,69,00,6e,00,65,00,0d,00,0a,00,\
32,00,6e,00,64,00,20,00,4c,00,69,00,6e,00,65,00,0d,00,0a,00,\
00,00

To encode ASCII into UTF-16LE, simply add a null byte following each ASCII code value. REG_SZ values must terminate with a null character (,00,00) in UTF-16LE notation.

Import the registry change in the batch file REG.EXE IMPORT MULTILINETEXT.REG.

The example uses the Environment key because it is convenient, not because it is particularly useful to add such data to environment variables. One may use RegEdit to verify that the imported REG_SZ data contains the CRLF characters.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the new answer. I'll try that out next time I have a similar issue.
This looks terrible, logical, and doable az the same time.
3

If you're not constrained to a scripting language, you can do it in C# with

Registry.CurrentUser.OpenSubKey(@"software\classes\something", true).SetValue("some key", "sometext\nothertext", RegistryValueKind.String);

1 Comment

Thanks but I'm fine with doing this from a program or even other scripting languages I was just hoping to do it without adding any more dependencies or complication
2

You could create a VBScript(.vbs) file and just call it from a batch file, assuming you're doing other things in the batch other than this registry change. In vbscript you would be looking at something like:

set WSHShell = CreateObject("WScript.Shell")  
WSHShell.RegWrite "HKEY_LOCAL_MACHINE\SOMEKEY", "value", "type"

You should be able to find the possible type values using Google.

1 Comment

The vbscript idea solved my problem. The script engine is standard on the windows xp platform I need to run on. To add new lines (0x0a) in vbscripts I used & vbLf
0

Another approach -- that is much easier to read and maintain -- is to use a PowerShell script. Run PowerShell as Admin.


# SetLegalNotice_AsAdmin.ps1

# Define multi-line legal notice registry entry

Push-Location

Set-Location -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\

$contentCaption="Legal Notice"

$contentNotice= @"

This is a very long string that runs to many lines.

You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only.

By using this IS (which includes any device attached to this IS), you consent to the following conditions:

-The USG routinely intercepts and monitors communications on this IS for purposes including, but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence (CI) investigations.

etc...

"@

# Caption

New-ItemProperty -Path . -Name legalnoticetext -PropertyType MultiString -Value $contentCaption -Force

# Notice

New-ItemProperty -Path . -Name legalnoticetext -PropertyType MultiString -Value $contentNotice -Force

Pop-Location

enter image description here

Comments

0

For just (REG_SZ) String Value(s) it's simple.

1) Through Command Prompt:
REG /?
REG [QUERY|ADD|DELETE|COPY|SAVE|RESTORE|LOAD|UNLOAD|COMPARE|EXPORT|IMPORT|FLAGS] /?

> reg add /?
REG ADD [HK...\path\to\KeyName] [/v ValueName | /ve (EmptyValueName)(Default)]
 [/t DataType] [/s (Separator)] [/d DataValue] [/f (Force overwriting)]
. . .

REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control" /v WaitToKillServiceTimeout /t REG_SZ /d 5000
(i) Could be added also to a .cmd/.bat file, to including multi line commands or use & or && between the commands in only one string at Command Prompt.

REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control" /v WaitToKillServiceTimeout /t REG_SZ /d 5000 & REG ADD "HKEY_CURRENT_USER\Console" /v ScreenColors /t REG_DWORD /d 0x0000000f /f

Note the /f switch at the end of every reg add command. If not exist, you will questioned about overwriting. Value WaitToKillServiceTimeout exists, overwrite(Yes/No)?

_ _ _ _ _ _ _ _

2) Through .reg file:

This way is much more convenient if you want to add/edit a lot of values and/or also many keys.
In a .reg file add as the following:

Windows Registry Editor Version 5.00

;this will change the waiting time to 5 seconds before Windows kill not responding programs.
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control]
"WaitToKillServiceTimeout"="5000"
Windows Registry Editor Version 5.00

; This will CREATE a sub Key named 'Example' under the 'Control' Key.
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Example]
"A-Reg-D_Word-ValueName"="SomeValueData"

; and this will DELETE the entire 'Example' Key and its contents.
[-HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Example]

You can also export a KeyName (from RegEdit.exe using R.Click, or from CMD using REG EXPORT /?) to a .reg file, back it up, or/and modify it and run it.
(i) Always leave empty line after the (mandatory to be the 1st) 'version line' in a .reg file.

Windows Registry Editor Version 5.00

;modified
;here exist only the default console colors
;some other values excluded
[HKEY_CURRENT_USER\Console]
"ScreenColors"=dword:0000000f
"PopupColors"=dword:000000f0

"ColorTable00"=dword:00000000
"ColorTable01"=dword:00800000
"ColorTable02"=dword:00008000
"ColorTable03"=dword:00808000
"ColorTable04"=dword:00000080
"ColorTable05"=dword:00800080
"ColorTable06"=dword:00008080
"ColorTable07"=dword:00c0c0c0
"ColorTable08"=dword:00808080
"ColorTable09"=dword:00ff0000
"ColorTable10"=dword:0000ff00
"ColorTable11"=dword:00ffff00
"ColorTable12"=dword:000000ff
"ColorTable13"=dword:00ff00ff
"ColorTable14"=dword:0000ffff
"ColorTable15"=dword:00ffffff

for example, if you run the above .reg file it will overwrite only the included values, and anything else in the already existed RegEdit.exe[HKEY_CURRENT_USER\Console] will stay untouched.

You can also add different Keys\subKeys, DataTypes and its values at the same .reg file.

Windows Registry Editor Version 5.00

; ::::::::::::::::::: by adonios77 :::: (supports Windows 7) :::::::::::::::::::
; R.Click + Shift to show - Context Menus      ("Extended"="")
; attributes              - file & directory
; inherited permissions   - file & directory
; ownership permissions   - file & directory & drive
; Kill All Not Responding Tasks - DesktopBackground
; ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

;ATTRIBUTES - file =============================================================
[HKEY_CLASSES_ROOT\*\shell]

[HKEY_CLASSES_ROOT\*\shell\Attributes]
"MUIVerb"="Attributes (r,a,s,h,i)"
"SubCommands"=""
"Extended"=""
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell]

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\aShow]
"MUIVerb"="Show current attributes"

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\aShow\Command]
@="cmd.exe /k attrib \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\bReset]
"MUIVerb"="Reset attributes (Remove)"

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\bReset\Command]
@="cmd.exe /k attrib -r -a -s -h -i \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\cReadOnlySet]
"MUIVerb"="Set Read-only attribute"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\cReadOnlySet\Command]
@="attrib +r \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\dReadOnlyRemove]
"MUIVerb"="Remove Read-only attribute"

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\dReadOnlyRemove\Command]
@="attrib -r \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\eHiddenSet]
"MUIVerb"="Set Hidden attribute"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\eHiddenSet\Command]
@="attrib +h \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\fHiddenRemove]
"MUIVerb"="Remove Hidden attribute"

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\fHiddenRemove\Command]
@="attrib -h \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\gSystemSet]
"MUIVerb"="Set System attribute"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\gSystemSet\Command]
@="attrib +s \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\hSystemRemove]
"MUIVerb"="Remove System attribute"

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\hSystemRemove\Command]
@="attrib -s \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\iArchiveSet]
"MUIVerb"="Remove Archive attribute"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\*\shell\Attributes\shell\iArchiveSet\Command]
@="attrib -a \"%1\""

; ATTRIBUTES - directory -------------------------------------------------------

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes]
"MUIVerb"="Attributes (r,a,s,h,i)"
"SubCommands"=""
"Extended"=""
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\aShow]
"MUIVerb"="Show current attributes"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\aShow\command]
@="cmd.exe /k attrib \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\bShow]
"MUIVerb"="Show attributes of this folder, subfolders and files"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\bShow\command]
@="cmd.exe /k attrib \"%1\" & attrib \"%1\\*.*\" /s /d"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\cReset]
"MUIVerb"="Reset attributes"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\cReset\command]
@="cmd.exe /c attrib -r -a -s -h -i \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\dReset]
"MUIVerb"="Reset attributes for this folder, subfolders and files"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\dReset\command]
@="cmd.exe /c attrib -r -a -s -h -i \"%1\" & attrib -r -a -s -h -i \"%1\\*.*\" /s /d"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\eReadOnlySet]
"CommandFlags"=dword:00000020
"MUIVerb"="Set Read-only attribute"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\eReadOnlySet\command]
@="cmd.exe /c attrib +r \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\fReadOnlySet]
"MUIVerb"="Set Read-only attribute to this folder, subfolders and files"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\fReadOnlySet\command]
@="cmd.exe /c attrib +r \"%1\" & attrib +r \"%1\\*.*\" /s"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\gReadOnlyRemove]
"MUIVerb"="Remove Read-only attribute"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\gReadOnlyRemove\command]
@="cmd.exe /c attrib -r \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\hReadOnlyRemove]
"MUIVerb"="Remove Read-only attribute from this folder and subfiles"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\hReadOnlyRemove\command]
@="cmd.exe /c attrib -r \"%1\" & attrib -r \"%1\\*.*\" /s"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\iHiddenSet]
"CommandFlags"=dword:00000020
"MUIVerb"="Set Hidden attribute"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\iHiddenSet\command]
@="cmd.exe /c attrib +h \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\jHiddenSet]
"MUIVerb"="Set Hidden attribute to this folder, subfolders and files"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\jHiddenSet\command]
@="cmd.exe /c attrib +h \"%1\" & attrib +h \"%1\\*.*\" /s /d"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\kHiddenRemove]
"MUIVerb"="Remove Hidden attribute"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\kHiddenRemove\command]
@="cmd.exe /c attrib -h \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\lHiddenRemove]
"MUIVerb"="Remove Hidden attribute from this folder, subfolders and files"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\lHiddenRemove\command]
@="cmd.exe /c attrib -h \"%1\" & attrib -h \"%1\\*.*\" /s /d"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\mSystemSet]
"CommandFlags"=dword:00000020
"MUIVerb"="Set System attribute"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\mSystemSet\command]
@="cmd.exe /c attrib +s \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\oSystemRemove]
"MUIVerb"="Remove System attribute"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\oSystemRemove\command]
@="cmd.exe /c attrib -h \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\qArchiveSet]
"CommandFlags"=dword:00000020
"MUIVerb"="Set Archive attribute"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\qArchiveSet\command]
@="cmd.exe /c attrib +a \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\sArchiveRemove]
"MUIVerb"="Remove Archive attribute"

[HKEY_CLASSES_ROOT\Directory\Shell\Attributes\Shell\sArchiveRemove\command]
@="cmd.exe /c attrib -a \"%1\""

;INHERITED PERMISSIONS - File ==================================================

[HKEY_CLASSES_ROOT\*\shell\InheritedPermissions]
"MUIVerb"="Inherited Permissions"
"HasLUAShield"=""
"NoWorkingDirectory"=""
"SubCommands"=""
"Extended"=""

[HKEY_CLASSES_ROOT\*\shell\InheritedPermissions\shell]

[HKEY_CLASSES_ROOT\*\shell\InheritedPermissions\shell\01EnableInheritance]
"MUIVerb"="Enable inheritance"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\InheritedPermissions\shell\01EnableInheritance\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /inheritance:e & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\*\shell\InheritedPermissions\shell\02DisableConvert]
"MUIVerb"="Disable inheritance and convert into explicit permissions"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\InheritedPermissions\shell\02DisableConvert\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /inheritance:d & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\*\shell\InheritedPermissions\shell\03DisableRemove]
"MUIVerb"="Disable inheritance and remove"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\InheritedPermissions\shell\03DisableRemove\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /inheritance:r & pause' -Verb runAs\""

; INHERITED PERMISSIONS - Directory --------------------------------------------

[HKEY_CLASSES_ROOT\Directory\shell\InheritedPermissions]
"MUIVerb"="Inherited Permissions"
"HasLUAShield"=""
"NoWorkingDirectory"=""
"SubCommands"=""
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\shell\InheritedPermissions\shell\01EnableInheritance]
"MUIVerb"="Enable inheritance"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\InheritedPermissions\shell\01EnableInheritance\command]
@="powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /inheritance:e & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Directory\shell\InheritedPermissions\shell\02DisableConvert]
"MUIVerb"="Disable inheritance and convert into explicit permissions"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\InheritedPermissions\shell\02DisableConvert\command]
@="powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /inheritance:d & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Directory\shell\InheritedPermissions\shell\03DisableRemove]
"MUIVerb"="Disable inheritance and remove"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\InheritedPermissions\shell\03DisableRemove\command]
@="powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /inheritance:r & pause' -Verb runAs\""

; OWNERSHIP PERMISSIONS - files ================================================

[HKEY_CLASSES_ROOT\*\shell\Ownership]
"Extended"=""
"HasLUAShield"=""
"MUIVerb"="Ownership"
"SubCommands"=""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell]

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\01View_Owner]
"MUIVerb"="See current owner"
"Icon"="imageres.dll,-1029"

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\01View_Owner\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit Get-ACL '%1'| Format-List -Property Owner"

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\02Set_Administrators]
"MUIVerb"="Change to Administrators"
"HasLUAShield"=""
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\02Set_Administrators\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Administrators\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Administrators\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\03Set_Everyone]
"MUIVerb"="Change to Everyone"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\03Set_Everyone\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Everyone\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Everyone\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\04Set_SYSTEM]
@="Change to SYSTEM"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\04Set_SYSTEM\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\05Set_TrustedInstaller]
"MUIVerb"="Change to TrustedInstaller"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\05Set_TrustedInstaller\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\06TakeOwnership]
@="Take Ownership (bypass)"
"HasLUAShield"=""
"NeverDefault"=""
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\06TakeOwnership\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c takeown /f \\\"%1\\\" && icacls \\\"%1\\\" /grant *S-1-3-4:F /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c takeown /f \\\"%1\\\" && icacls \\\"%1\\\" /grant *S-1-3-4:F /c /l & pause' -Verb runAs\""

; OWNERSHIP PERMISSIONS RESET NTFS 
[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\07ResetNTFSPermissions]
"MUIVerb"="Reset Permissions (NTFS)"
"CommandFlags"=dword:00000020
"HasLUAShield"=""
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\*\shell\Ownership\shell\07ResetNTFSPermissions\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd.exe -ArgumentList '/c icacls \\\"%1\\\" /reset & pause' -Verb RunAs\""

;-???---------------------------------------------------------------------------
[HKEY_CLASSES_ROOT\*\shell\removeproperties]
"ProgrammaticAccessOnly"="Apartment"

[HKEY_CLASSES_ROOT\*\shell\removeproperties\DropTarget]
"CLSID"="{09a28848-0e97-4cef-b950-cea037161155}"

; OWNERSHIP PERMISSIONS - directory --------------------------------------------

[HKEY_CLASSES_ROOT\Directory\shell\Ownership]
"MUIVerb"="Ownership"
"AppliesTo"="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)\")"
"Extended"=""
"HasLUAShield"=""
"NoWorkingDirectory"=""
"Position"="middle"
"SubCommands"=""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\01View_Owner]
@="See current owner"
"Icon"="imageres.dll,-1029"

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\01View_Owner\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit Get-ACL '%1'| Format-List -Property Owner"

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\02Set_Administrators]
@="Change to Administrators"
"HasLUAShield"=""
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\02Set_Administrators\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Administrators\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Administrators\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\03Set_Everyone]
@="Change to Everyone"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\03Set_Everyone\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Everyone\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Everyone\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\04Set_SYSTEM]
@="Change to SYSTEM"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\04Set_SYSTEM\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\05Set_TrustedInstaller]
@="Change to TrustedInstaller"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\05Set_TrustedInstaller\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /t /c /l & pause' -Verb runAs\""

; OWNERSHIP PERMISSIONS RESET NTFS 
[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\06ResetNTFSPermissions]
"MUIVerb"="Reset Permissions (NTFS)"
"CommandFlags"=dword:00000020
"HasLUAShield"=""
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\shell\06ResetNTFSPermissions\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd.exe -ArgumentList '/c icacls \\\"%1\\\" /reset & pause' -Verb RunAs\""

; OWNERSHIP PERMISSIONS - drive ------------------------------------------------

[HKEY_CLASSES_ROOT\Drive\shell\Ownership]
"MUIVerb"="Change Owner"
"AppliesTo"="NOT (System.ItemPathDisplay:=\"C:\\\")"
"Extended"=""
"HasLUAShield"=""
"NoWorkingDirectory"=""
"Position"="middle"
"SubCommands"=""

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\01View_Owner]
@="See current owner"
"Icon"="imageres.dll,-1029"

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\01View_Owner\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit Get-ACL '%1'| Format-List -Property Owner"


[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\02Set_Administrators]
@="Change to Administrators"
"HasLUAShield"=""
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\02Set_Administrators\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%1\\\" /setowner \"Administrators\" /c & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%1\\\" /setowner \"Administrators\" /c & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\03Set_Everyone]
@="Change to Everyone"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\03Set_Everyone\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/k icacls \"%1\\\" /setowner \"Everyone\" /c & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/k icacls \"%1\\\" /setowner \"Everyone\" /c & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\04Set_SYSTEM]
@="Change to SYSTEM"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\04Set_SYSTEM\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%1\\\" /setowner \"SYSTEM\" /c & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%1\\\" /setowner \"SYSTEM\" /c & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\04Set_TrustedInstaller]
@="Change to TrustedInstaller"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\04Set_TrustedInstaller\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /c & pause' -Verb runAs\""
"IsolatedCommand"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /c & pause' -Verb runAs\""

; OWNERSHIP PERMISSIONS RESET NTFS 
[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\05ResetNTFSPermissions]
"MUIVerb"="Reset Permissions (NTFS)"
"CommandFlags"=dword:00000020
"HasLUAShield"=""
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Drive\shell\Ownership\shell\05ResetNTFSPermissions\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -command \"Start-Process cmd.exe -ArgumentList '/c icacls \\\"%1\\\" /reset & pause' -Verb RunAs\""

; Kill All Not Responding Tasks - DesktopBackground ============================
[HKEY_CLASSES_ROOT\DesktopBackground\Shell\KillNotResponding]
"icon"="taskmgr.exe,-30651"
"MUIverb"="Kill not responding tasks"
"Position"="Top"

[HKEY_CLASSES_ROOT\DesktopBackground\shell\KillNotResponding\Command]
@="cmd.exe /K tasklist.exe /FI \"STATUS eq NOT RESPONDING\" & taskkill.exe /F /FI \"STATUS eq NOT RESPONDING\" && timeout /T 4 && exit || @echo.———————————&echo.Trying with elevated permissions && powershell Start-Process -wait \"cmd.exe\" -verb runAs -ArgumentList \"'/C taskkill /F /FI \\\"STATUS eq NOT RESPONDING\\\" & timeout /T 4\"' && exit"

enter image description here

To remove it run the following:

Windows Registry Editor Version 5.00

; :::::::::::::::::::: by adonios77    (supports Windows 7) ::::::::::::::::::::
; R.Click + Shift to show menus ("Extended"="")
; Includes:
; attributes              - file & directory
; inherited permissions   - file & directory
; ownership - permissions - file & directory & drive
; ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

;ATTRIBUTES - file =============================================================
[-HKEY_CLASSES_ROOT\*\shell\Attributes]

; ATTRIBUTES - directory --------------------------------------------------------
[-HKEY_CLASSES_ROOT\Directory\Shell\Attributes]

;INHERITED PERMISSIONS - File ==================================================
[-HKEY_CLASSES_ROOT\*\shell\InheritedPermissions]

; INHERITED PERMISSIONS - Directory --------------------------------------------
[-HKEY_CLASSES_ROOT\Directory\shell\InheritedPermissions]

; OWNERSHIP PERMISSIONS - files ================================================
[-HKEY_CLASSES_ROOT\*\shell\Ownership]

;-???---------------------------------------------------------------------------
[-HKEY_CLASSES_ROOT\*\shell\removeproperties]
[-HKEY_CLASSES_ROOT\*\shell\removeproperties\DropTarget]

; OWNERSHIP PERMISSIONS - directory --------------------------------------------
[-HKEY_CLASSES_ROOT\Directory\shell\Ownership]

; OWNERSHIP PERMISSIONS - drive ------------------------------------------------
[-HKEY_CLASSES_ROOT\Drive\shell\Ownership]

; Kill All Not Responding Tasks - DesktopBackground ============================
[-HKEY_CLASSES_ROOT\DesktopBackground\Shell\KillNotResponding]

I have collected various tweaks - modifications about context-menus from 'winaero.com' and amended them and incorporated into the .reg file above, as example to the question.
Take a look here: winaero.com/add-inherited-permissions-context-menu-windows-10/

To create a "REG_MULTI_SZ" or "REG_EXPAND_SZ" you must mess with HEX...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.