- Joined
- Aug 21, 2010
- Sythe Gold
- 7
- Messages
- 1,845
EDIT: Found the solution:
Close please.
Howdy, so basically I'm writing a PowerShell script that will create all of the folders, keys, and such and make the changes to the DWORD value. This will prevent Windows from automatically restarting my computer without my permission.
Anyway, my problem is that when I get to the last couple lines. I'm trying to create a DWORD key and then change the value to 1, but I keep getting these errors:
I've tried changing the ACL permissions but the same errors occur. I've even tried manually changing permissions without success.
Here's the code:
Code:
Set-ExecutionPolicy RemoteSigned
Start-Process powershell -Verb runAs
Push-Location
Set-Location HKLM:
Test-Path .\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\
New-Item -Path .\SOFTWARE\Policies\Microsoft\Windows\ -Name WindowsUpdate
Pop-Location
Push-Location
Set-Location HKLM:
Test-Path .\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
New-Item -Path .\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name AU
Pop-Location
$domainName = [Environment]::UserDomainName
$username = [Environment]::UserName
$ownerName = $domainName + "\" + $username
$acl = Get-Acl HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
$rule = New-Object System.Security.AccessControl.RegistryAccessRule ($ownerName,"FullControl","Allow")
$acl.SetAccessRule($rule)
$acl |Set-Acl -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
New-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoRebootWithLoggedOnUsers" -Value 1 -PropertyType "DWord"
Close please.
Howdy, so basically I'm writing a PowerShell script that will create all of the folders, keys, and such and make the changes to the DWORD value. This will prevent Windows from automatically restarting my computer without my permission.
Anyway, my problem is that when I get to the last couple lines. I'm trying to create a DWORD key and then change the value to 1, but I keep getting these errors:
Code:
[B][COLOR="Red"]Set-Item : Requested registry access is not allowed.
At line:1 char:9
+ Set-Item <<<< -Path HKCU:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Value "NoAutoRebootWithLoggedOnUsers key"
+ CategoryInfo : PermissionDenied: (HKEY_CURRENT_US...indowsUpdate\AU:String) [Set-Item], SecurityException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.SetItemCommand
New-Item : Requested registry access is not allowed.
At line:2 char:9
+ New-Item <<<< -Path HKCU:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Value "1"
+ CategoryInfo : PermissionDenied: (HKEY_CURRENT_US...s\WindowsUpdate:String) [New-Item], SecurityException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.NewItemCommand[/COLOR][/B]
I've tried changing the ACL permissions but the same errors occur. I've even tried manually changing permissions without success.
Here's the code:
Code:
Push-Location
Set-Location HKLM:
Test-Path .\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\
New-Item -Path .\SOFTWARE\Policies\Microsoft\Windows\ -Name WindowsUpdate
Pop-Location
Push-Location
Set-Location HKLM:
Test-Path .\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
New-Item -Path .\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name AU
Pop-Location
$domainName = [Environment]::UserDomainName
$username = [Environment]::UserName
$ownerName = $domainName + "\" + $username
$acl = Get-Acl HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
$rule = New-Object System.Security.AccessControl.RegistryAccessRule ($ownerName,"FullControl","Allow")
$acl.SetAccessRule($rule)
$acl |Set-Acl -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
Set-Item -Path HKCU:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Value "NoAutoRebootWithLoggedOnUsers key"
New-Item -Path HKCU:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Value "1"



