2017-05-29 5 views
0

レジストリキーといくつかの値を作成し、継承を無効にしてアクセス許可を設定しようとしています(実際にはアクセス許可なし)と値?レジストリキーと値を作成し、継承を無効にします。アクセス許可を無効にします。

継承をオンに設定すると多くの投稿が表示されますが、それを無効にしてアクセス許可を設定することはあまりありません。私は「なぜこれをやりたいの?それはパートナーの要件です。

以下のコードはオブジェクトを作成しますが、アクセス許可で何もしないようです。終了状態ではありませんが、継承がオンになっているため、何もしません。 私が必要とするのは、継承を無効にし、アクセス許可を設定しないことです。

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

    } 
関連する問題