2012-10-09 83 views
0

我正在嘗試使用icacls修改文件上的ACL。我希望此文件由管理員擁有,並且只能由管理員訪問。我發現如何讓管理員成爲文件的所有者,並且我知道如何從安全列表中刪除一個組,但是我不知道如何刪除除管理員組以外的所有組,但是如果我不知道該組的名稱其他團體。icacls從ACL中刪除所有組

我正在尋找一種方法來告訴Windows,我只想讓管理員訪問該文件並刪除任何其他用戶/組。

我試過使用通配符,但它不起作用。

這裏是我的腳本:

$domain  = [Environment]::UserDomainName 
$user  = [Environment]::UserName 
icacls $myinvocation.mycommand.path /setowner "$domain\$user" /T 
icacls $myinvocation.mycommand.path /grant "$domain\$user" 

icacls $myinvocation.mycommand.path 

回答

2

從理論上講,你可以使用授權之後:r(見Docs)。但是,實際上我無法完成這項工作。我認爲:r表示「僅替換指定用戶」的替換權限

我已經在Powershell中測試了以下解決方案,但它工作正常。

# Reset the folder to just it's inherited permissions 
icaclsname c:\temp\test /reset 

# Then, disable inheritance and remove all inherited permissions 
icacls c:\temp\test /inheritance:r 

# Note the :r after grant. It's not now needed, but I've left it in anyway. 
# Permissions replace previously granted explicit permissions. 
# Also note the :F, where : is escaped with `. This grants FULL CONTROL. 
# You can replace F with whatever level of control is required for you. 
icacls c:\temp\test /grant:r $domain\$user`:F 
+0

好一個RB但不幸的,R生成的PowerShell :( 一個錯誤,我想我將不得不使用設置的ACL,而不是... – Bluz

+0

@Bluz對不起 - 沒有看到PowerShell的標籤。我已經完全改變了我的答案 - 請現在試試這個(這次我已經測試過了) –

+0

太棒了!這個新腳本完美地完成了這項工作!非常感謝!:D – Bluz