2017-05-29 1 views
0

J'essaie de créer une clé de registre et certaines valeurs, puis désactiver l'héritage et définir des autorisations (En fait, aucune autorisation) Est-ce possible de faire comme vous créez les clés et les valeurs?Créer une clé de registre et des valeurs, désactiver l'héritage définir aucune autorisation

Je vois beaucoup de messages sur la définition de l'héritage, mais pas beaucoup pour le désactiver et ne définir aucune autorisation. Je réalise "pourquoi voudriez-vous faire cela?" mais c'est une exigence du partenaire.

Le code ci-dessous crée l'objet mais semble ne rien faire avec des autorisations. Bien que ce ne soit pas l'état final, il ne fait rien parce que l'héritage est activé. Donc, ce dont j'ai besoin est désactiver l'héritage et ne définir aucune autorisation.

$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

Que voulez-vous dire par "définir aucune autorisation"? –

+0

Je veux que les permissions soient vides, c'est-à-dire que personne n'a accès à la clé à moins d'y entrer et d'en prendre explicitement possession, etc. – Bob

+1

Ne faites pas cela. C'est une exigence stupide qui ne résoudra pas n'importe quel problème que votre partenaire pense que ce serait, mais créera des dommages collatéraux en cours de route. –

Répondre

0

Ceci est en fait la réponse, Tort ou à raison d'un point de vue principale, il fonctionne.

[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') 

    }