2017-05-29 209 views
0

我想創建一個註冊表項和一些值,然後關閉繼承並設置權限(實際上沒有權限)這是可能的,因爲你正在創建密鑰和價值?創建註冊表項和值,禁用繼承設置沒有權限

我看到很多關於將繼承設置爲on的帖子,但沒有太多的關閉並且沒有設置權限。我意識到「你爲什麼要這麼做?」但這是合作伙伴的要求。

下面的代碼創建對象,但似乎什麼也不做權限。儘管它不是最終狀態,但它不會執行任何操作,因爲繼承已打開。 所以我需要的是禁用繼承並設置沒有權限。

$ResgistryKeyPath = "HKLM:\Software\Policies\Microsoft\Windows\RTestBob" 
New-Item $ResgistryKeyPath -Force 
New-ItemProperty -Path $ResgistryKeyPath -Propertytype DWORD -Name 
Deny_Write -Value 1 -Force | Out-Null 
$AddACL = New-Object System.Security.AccessControl.RegistryAccessRule ("Domain Admins", "FullControl", "Allow") 
$AddACL = New-Object System.Security.AccessControl.RegistryAccessRule ("auth\me", "FullControl", "ObjectInherit,ContainerInherit", "None", "Allow") 
+0

你是什麼意思「設置沒有權限」? –

+0

我想要的權限是空白的,沒有人有權訪問該密鑰,除非他們進入並明確擁有所有權等。 – Bob

+1

不要這樣做。這是一個愚蠢的要求,不能解決你的伴侶認爲會出現的任何問題,但會一路造成附帶傷害。 –

回答

0

這實際上是答案,右或從它的工作主要觀點來看是錯誤的。

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') 
#Set some variables 
$RegistryKeyPath1 = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b" 
$RegistryKeyPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices" 
$DisableInheritance=$true 
$PreserveInheritanceIfDisabled =$True 

#Create the registry keys 
Try { 
New-Item $RegistryKeyPath1 -Force | Out-Null 
New-ItemProperty -path $RegistryKeyPath1 -propertyType DWORD -Name Deny_Write -Value 1 -Force | Out-Null 
New-ItemProperty -path $RegistryKeyPath1 -propertyType DWORD -Name Deny_Read -Value 1 -Force | Out-Null 
New-ItemProperty -path $RegistryKeyPath1 -propertyType DWORD -Name Deny_Execute -Value 1 -Force | Out-Null 
New-ItemProperty -path $RegistryKeyPath -propertyType DWORD -Name Deny_All -Value 1 -Force | Out-Null 
} 

Catch 
{ 
[System.Windows.forms.MessageBox]::Show('Key exists and an error has occured. Please check the registry manually in this location','Error','OKCancel','Error') ; exit 

    } 

Try { 

#Remove Inheritance - Inheritance is removed from both keys so that if one is done the other will have to be also. 
$acl = Get-Acl $RegistryKeyPath1 
$acl.SetAccessRuleProtection($DisableInheritance, $preserveInheritanceIfDisabled) 
Set-Acl $RegistryKeyPath1 $acl 
    $acl1 = Get-Acl $RegistryKeyPath 
    $acl1.SetAccessRuleProtection($DisableInheritance, $preserveInheritanceIfDisabled) 
    Set-Acl $RegistryKeyPath $acl1 

    #Remove Permissions 
    $aclPerm1 = get-acl $RegistryKeyPath1 
    $aclPerm1.PurgeAccessRules([System.Security.Principal.NTAccount] "Authenticated Users") #Administrators, SYSTEM, ALL APPLICATION PACKAGES 
set-acl $RegistryKeyPath1 $aclPerm1 
$aclPerm1.PurgeAccessRules([System.Security.Principal.NTAccount] "Administrators") #Administrators, SYSTEM, ALL APPLICATION PACKAGES 
set-acl $RegistryKeyPath1 $aclperm1 

    $aclPerm = get-acl $RegistryKeyPath 
    $aclPerm.PurgeAccessRules([System.Security.Principal.NTAccount] "Authenticated Users") #Administrators, SYSTEM, ALL APPLICATION PACKAGES 
    set-acl $RegistryKeyPath $aclPerm 
    $aclPerm.PurgeAccessRules([System.Security.Principal.NTAccount] "Administrators") #Administrators, SYSTEM, ALL APPLICATION PACKAGES 
    set-acl $RegistryKeyPath $aclperm 
    [System.Windows.forms.MessageBox]::Show('Successfully Implemented!','Success','OKCancel','Information') 
    } 
    Catch 
    { 
    [System.Windows.forms.MessageBox]::Show('An error has occured. Please check the registry manually in this location','Error','OKCancel','Error') 

    }