
更改 Windows 目錄中可執行檔的所有權(explorer.exe
、regedit.exe
等)後,我似乎無法將其改回TrustedInstaller
使用icacls.exe
.使用 GUI 方法(屬性→安全性→進階→所有者)但工作正常。
對Windows下的任何其他文件做同樣的事情,即不是可執行文件,工作正常。在安全模式下嘗試了同樣的方法,沒有運氣。
這些是我正在使用的兩個基本命令:
takeown /F C:\Windows\explorer.exe /A
icacls C:\Windows\explorer.exe /setowner "NT SERVICE\TrustedInstaller"
編輯:忘了提及我收到錯誤「被拒絕訪問」。
C:\Windows\System32>takeown /F c:\Windows\explorer.exe /A
SUCCESS: The file (or folder): "c:\Windows\explorer.exe" now owned by the administrators group.
C:\Windows\System32>icacls c:\Windows\explorer.exe /setowner "NT SERVICE\TrustedInstaller"
c:\Windows\explorer.exe: Access is denied.
Successfully processed 0 files; Failed processing 1 files
答案1
所以標題說恢復 TrustedInstaller。
似乎有一個缺失的部分;刪除新增的管理員群組權限。
takeown /F "C:\Windows\regedit.exe" /A
/F - file to become owner of
/A - means it will set the users group (ie. Administrators, not userxyz)
icacls "C:\Windows\regedit.exe" /grant Administrators:F
/grant - will add permissions
:F - Full Control
icacls "C:\Windows\regedit.exe" /setowner "NT SERVICE\TrustedInstaller"
/setowner - new owner
icacls "C:\Windows\regedit.exe" /grant:r Administrators:RX
/grant:r - will set permissions (removing higher ones)
:RX - Read and Execute
答案2
此指令只有在授予管理員群組完全權限後才有效,即:
icacls c:\Windows\explorer.exe /grant Administrators:f
由於某種原因,即使授予“修改”似乎也還不夠。
答案3
正如您在答案中發現的那樣,問題在於設定檔案的所有者需要特殊權限,特別是「取得所有權」。 ACL 編輯器 GUI 能夠設定擁有者的原因是它啟用了SeTakeOwnershipPrivilege
特權,它允許覆蓋該訪問檢查。以管理員身份運行的程式具有此特權,但他們必須在使用它之前明確啟用它,但顯然icacls
沒有。
方便的是,進程預設繼承其父進程的權限,因此,如果您可以為呼叫的命令提示字元啟用該權限icacls
,則該實用程式也會啟用該權限,並且能夠設定擁有者。您可以使用我的開源實用程式SprintDLL呼叫適當的 Win32 函數以啟用 SprintDLL 父進程中的權限(命令提示字元):
SprintDLL call kernel32.dll!OpenProcess /return native /into prochandle (int 0x400, int 0, slotdata parentpid); newslot native token; call advapi32.dll!OpenProcessToken /return int (slotdata prochandle, int 0x20, slotptr token); newslot block luid = int 0, int 0; call advapi32.dll!LookupPrivilegeValueW /return int (nullptr, lpwstr "SeTakeOwnershipPrivilege", slotptr luid); newslot block privs = int 1, slotdata luid, int 2; call advapi32.dll!AdjustTokenPrivileges /return int (slotdata token, int 0, slotptr privs, slotsize privs as int, nullptr, nullptr)
如果它有效,輸出將顯示所有三個被呼叫的函數都傳回 1 icacls
。
答案4
這在 64 位元系統上對我有用(以及我的問題)...
icacls c:\Windows\SysWOW64\usercpl.dll /grant Administrators:f
icacls "C:\Windows\SysWOW64\usercpl.dll" /setowner "NT SERVICE\TrustedInstaller"
/setowner - 新所有者