Jump to content
Sign in to follow this  
Turtlix21

Problem with registry permission

Recommended Posts

Turtlix21

I'm trying to make a simple program which will turn off all audio devices, except chosen one. I found registry locations and keys to make it, but I only can read values from this location. All attemps to make a new one or delete a key returns 0 and sets extended to 5 ("unable to open requested main key" and "unable to remote connect to the registry"). It looks like autoit script only has permissions to read values, I added #ReguireAdmin in first line but It changed nothing. I also tried to change permissions in registry but it all time ends with "access denied".

#RequireAdmin
;~ $Return = RegWrite("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{96b80f31-032c-46e7-bde0-5485e67679ce}", "DeviceState", "REG_DWORD", 1) ;Return: 0 ;extended: 5 (doesn't work) Goal is to make it works

$Return = RegWrite("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion", "State", "REG_DWORD", "1") ;Return: 1 ;extended: 0 (works)
RegDelete("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion", "State")

;~ $Return = RegWrite("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices", "State", "REG_DWORD", "1") ;Return: 0 ;extended: 5 (doesn't work)
;~ RegDelete("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices", "State")

MsgBox(0, "", "Returned value: " & $Return & @CRLF & "Extended: " & @extended)

Problem starts in "MMDevices" location, in lower stages of location everythig is fine.

Share this post


Link to post
Share on other sites
BrewManNH

For one thing, the RegWrite and RegDelete commands aren't referencing the same locations as the commented out code. Also, a simple right click on the key and selecting permissions would have told you that administrators and users have no rights to delete any values or the key itself, and very limited rights to change anything in there.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Turtlix21

So, which group of permissions autoit script is using ? (ALL APPLICATION PACKAGES, User, Administrator, AudioEndpointBuilder or Audiosrv) I also don't know how to change permissions in MMDevices becouse all time "access danied", any ideas ?

Share this post


Link to post
Share on other sites
BrewManNH

You don't have access to change it, it's controlled by the AudioSrv permission group. And only the AudoiSrv group can delete anything in that key. What ever it is you're trying to do in there isn't possible by changing or deleting keys/values in that section.

What do you mean by "turn off all audio devices"? What is it you're attempting to do by turning them off? I'm sure it can be achieved in another way than trying to brute force a registry setting.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Turtlix21

I want to change audio output by turning off all audio devices except one (eg. I want to change output to speakers, from headphones). I found location of registry key in Internet which change the state of device ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{DEVICE-HASH}", "DeviceState"). When DeviceState is equal 1 device is on and when it's equal 268435457 device is off. I've made this and everythig looks fine, but I can't write in registry from script (I can write and delete keys by manually using regedit.exe)

#RequireAdmin
#include <array.au3>

Func AudioOutput($DeviceName)
    Local $i = 0
    Local $Devices[0 + 1][3 + 1]
    Local $RegistryLocation = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render"
    While 1
        $i += 1
        Local $DeviceID = RegEnumKey($RegistryLocation, $i)
        If $DeviceID = "" Then ExitLoop
        If RegRead($RegistryLocation & "\" & $DeviceID, "Role:0") <> "" Then
            If RegRead($RegistryLocation & "\" & $DeviceID, "DeviceState") = 1 Then
                Local $IsOn = 1
            Else
                Local $IsOn = 0
            EndIf
            _ArrayAdd($Devices, $DeviceID & "|" & RegRead($RegistryLocation & "\" & $DeviceID & "\Properties", "{a45c254e-df1c-4efd-8020-67d146a850e0},2") & "|" & $IsOn, 1)
        EndIf
    WEnd
    _ArrayDisplay($Devices)
    $WhereDeviceInArray = _ArraySearch($Devices, $DeviceName)
    If $WhereDeviceInArray = -1 Then
        Return -1
    ElseIf $Devices[$WhereDeviceInArray][3] = 1 Then
        Return 2
    Else
        For $i = 1 To UBound($Devices)
            RegWrite($RegistryLocation & "\" & $Devices[$i][1], "DeviceState", "REG_DWORD", 268435457)
        Next
        RegWrite($RegistryLocation & "\" & $Devices[$WhereDeviceInArray][1], "DeviceState", "REG_DWORD", 1)
        Return 1
    EndIf
EndFunc   ;==>AudioOutput


MsgBox(0, "", AudioOutput("Speakers"))

Changing audio output by registry looks like the most unproblematic way.

Edited by Turtlix21

Share this post


Link to post
Share on other sites
BrewManNH

Repeating yourself isn't helping. Tell us what you want to do, exactly, and then we can help. You've already found out you can't do it by a script using those keys in the registry, so there needs to be another method. That method can't be determined until you tell us what you're trying to do.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Turtlix21

I want to make function to change audio output, it's all.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.