如何在 .reg 文件中以管理员身份执行 cmd 来更改所有权

如何在 .reg 文件中以管理员身份执行 cmd 来更改所有权

我正在努力让它正常工作。这个 .reg 在导入时表面上可以工作,但在执行时,我收到“此安全 ID 可能无法指定为此对象的所有者”的提示

我推测这是因为 cmd 没有以管理员身份启动。有人能建议如何更改命令吗?从过去遇到类似要求的经历来看,我认为您必须先使用 powershell 打开 cmd 或类似的东西?

这是注册文件

[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership]
"HasLUAShield"=""
"MUIVerb"="Restore Ownership"
"NoWorkingDirectory"=""
"NeverDefault"=""
"SubCommands"=""


[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\Shell]


[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\Shell\RestoreOwnershipSYSTEM]
"HasLUAShield"=""
"MUIVerb"="Restore to System"


[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\Shell\RestoreOwnershipSYSTEM\command]
@="cmd.exe /c icacls \"%1\" /setowner \"SYSTEM\" /t /c & pause"
"IsolatedCommand"="cmd.exe /c icacls \"%1\" /setowner \"SYSTEM\" /t /c & pause"


[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\Shell\RestoreOwnershipTrustedInstaller]
"HasLUAShield"=""
"MUIVerb"="Restore to TrustedInstaller"


[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\Shell\RestoreOwnershipTrustedInstaller\command]
@="cmd.exe /c icacls \"%1\" /setowner \"NT Service\\TrustedInstaller\" /t /c & pause"
"IsolatedCommand"="cmd.exe /c icacls \"%1\" /setowner \"NT Service\\TrustedInstaller\" /t /c & pause"


[HKEY_CLASSES_ROOT\Directory\shell\RestoreOwnership]
"HasLUAShield"=""
"MUIVerb"="Restore Ownership"
"NoWorkingDirectory"=""
"NeverDefault"=""
"SubCommands"=""


[HKEY_CLASSES_ROOT\Directory\shell\RestoreOwnership\Shell]


[HKEY_CLASSES_ROOT\Directory\shell\RestoreOwnership\Shell\RestoreOwnershipSYSTEM]
"HasLUAShield"=""
"MUIVerb"="Restore to System"


[HKEY_CLASSES_ROOT\Directory\shell\RestoreOwnership\Shell\RestoreOwnershipSYSTEM\command]
@="cmd.exe /c icacls \"%1\" /setowner \"SYSTEM\" /t /c & pause"
"IsolatedCommand"="cmd.exe /c icacls \"%1\" /setowner \"SYSTEM\" /t /c & pause"


[HKEY_CLASSES_ROOT\Directory\shell\RestoreOwnership\Shell\RestoreOwnershipTrustedInstaller]
"HasLUAShield"=""
"MUIVerb"="Restore to TrustedInstaller"


[HKEY_CLASSES_ROOT\Directory\shell\RestoreOwnership\Shell\RestoreOwnershipTrustedInstaller\command]
@="cmd.exe /c icacls \"%1\" /setowner \"NT Service\\TrustedInstaller\" /t /c & pause"
"IsolatedCommand"="cmd.exe /c icacls \"%1\" /setowner \"NT Service\\TrustedInstaller\" /t /c & pause"

嗯,我的系统版本正在运行

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


[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\shell\RestoreOwnershipSYSTEM]
@="Restore Ownership SYSTEM"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\shell\RestoreOwnershipSYSTEM\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""


[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\shell\RestoreOwnershipTrustedInstaller]
@="Restore Ownership TrustedInstaller"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\*\shell\RestoreOwnership\shell\RestoreOwnershipTrustedInstaller\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"NT Service\\TrustedInstaller\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"NT Service\\TrustedInstaller\" /t /c /l & pause' -Verb runAs\""

不幸的是,TrustedInstaller 仍然失败了

Invalid parameter "Service\TrustedInstaller"

我知道这一定是一些我所忽略的非常简单的事情......

答案1

最终答案。一切都围绕着格式展开。

Windows Registry Editor Version 5.00

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

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell]

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell\flyout01]
"HasLUAShield"=""
"MUIVerb"="Take ownership"

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell\flyout01\command]
@="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\""

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell\flyout02]
"CommandFlags"=dword:00000020
"HasLUAShield"=""
"MUIVerb"="Restore to administrators"

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell\flyout02\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Administrators\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Administrators\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell\flyout03]
"HasLUAShield"=""
"MUIVerb"="Restore to system"

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell\flyout03\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell\flyout04]
"HasLUAShield"=""
"MUIVerb"="Restore to trustedinstaller"

[HKEY_CLASSES_ROOT\*\shell\Ownership\Shell\flyout04\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /t /c /l & pause' -Verb runAs\""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership]
"HasLUAShield"=""
"MUIVerb"="Ownership"
"NoWorkingDirectory"=""
"NeverDefault"=""
"SubCommands"=""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\Shell]

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\Shell\flyout01]
"HasLUAShield"=""
"MUIVerb"="Take ownership"

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\Shell\flyout01\command]
@="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\""

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\Shell\flyout02]
"CommandFlags"=dword:00000020
"HasLUAShield"=""
"MUIVerb"="Restore to administrators"

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\Shell\flyout02\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"Administrators\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="powershell -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\flyout03]
"HasLUAShield"=""
"MUIVerb"="Restore to system"

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\Shell\flyout03\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"SYSTEM\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="powershell -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\flyout04]
"HasLUAShield"=""
"MUIVerb"="Restore to trustedinstaller"

[HKEY_CLASSES_ROOT\Directory\shell\Ownership\Shell\flyout04\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c icacls \\\"%1\\\" /setowner \"\"\"NT Service\\TrustedInstaller\"\"\" /t /c /l & pause' -Verb runAs\""

相关内容