Pls, How i have to solve this problème?
# set disable:
If ($Set_value -eq 0){ (set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\RadioManagement\SystemRadioState").'1'}
Else { (set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\RadioManagement\SystemRadioState").'0'}
# set enable:
If ($Set_value -eq 1){ (set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\RadioManagement\SystemRadioState").'0'}
Else { (set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\RadioManagement\SystemRadioState").'1'}
Thanks for your help @
CodePudding user response:
There are some problems with your code, starting with the fact that you do have a complete registry path to the registry KEY, but do not supply the entry Name to update.
The second thing is that you need to run it with Admin permissions, since you are trying to alter a registry vaue in the HKEY_LOCAL_MACHINE hive.
You do not say what is in variable $Set_value, but I can imagine this exercise is to toggle the default value in the registry path from 1 to 0 and vice-versa ?
In that case try
$regPath = 'HKLM:\System\CurrentControlSet\Control\RadioManagement\SystemRadioState'
# assuming you obtained the value in this variable like this:
$Set_value = Get-ItemPropertyValue -Path $regPath -Name '(Default)'
# show the current status
$airplaneMode = if ($Set_value) {'Enabled'} else {'Disabled'}
Write-Host "Airplane mode is currently $airplaneMode"
# now toggle it. To make sure the value can only be 1 or 0, I'm using some [math] static methods:
$Set_value = 1 - [math]::Abs([math]::Sign($Set_value)) # 1 --> 0 and 0 --> 1
# and set the new default value
Set-ItemProperty -Path $regPath -Name '(Default)' -Value $Set_value -Type DWord
# show the updated status
$airplaneMode = if ($Set_value) {'Enabled'} else {'Disabled'}
Write-Host "Airplane mode is now $airplaneMode"
CodePudding user response:
Arenas,
Since your $Set_Value can only be 1 or 0 you only need one if test. Also since the value for that item is a Reg_DWORD you want a number as the value not a string.
As to the permission denied you need to run as Administrator. If that doesn't work you need to see your admin to get your access permissions changed.
Edited: As per Theo's post below I added the -Name parameter. I saw a post where it said it was unnecessary for the Default value but obviously that was incorrect!
$RegPath = "HKLM:\System\CurrentControlSet\Control\RadioManagement\SystemRadioState"
If ($Set_value -eq 0 ){ set-ItemProperty -Path "$RegPath" -Name '(Default)' -Value 1 }
Else { set-ItemProperty -Path "$RegPath" -Name '(Default)' -Value 0 }
