Registry Key Contains Comma - How To Escape It?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 14:05

As you can see in the following picture, all these Registry keys contain comma,
How can I escape them?
I'm using RegRead and RegWrite.
Image

I have searched and found this:
https://autohotkey.com/board/topic/96759-run-a-filename-that-contains-a-comma/
But I'm scared to try it. I don't wanna mess up my Registry xD

Thanks very much!
ilhom
Posts: 52
Joined: 19 Aug 2019, 17:58

Re: Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 15:51

That post you linked is correct. Check out EscapeChar to see how an accent is used for certain characters.

https://www.autohotkey.com/docs/commands/_EscapeChar.htm
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 16:12

But RegWrite isn't working.. although I'm running AHK with UAC access:

Code: Select all

072: RegWrite,REG_BINARY,HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{d0649ed1-77fc-4bd5-a5f6-cf5600c5136f}\Properties,{24dbb0fc-9311-4b3d-9cf0-18ff155639d4},1,%Listen1Ch
073: }
077: Return (60.08)
Here's my actual code:

Code: Select all

x::
regread,Listen1,HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{d0649ed1-77fc-4bd5-a5f6-cf5600c5136f}\Properties,{24dbb0fc-9311-4b3d-9cf0-18ff155639d4}`,1
Listen1State := SubStr(Listen1, 17, 4)
Listen1First := SubStr(Listen1, 1, 16)
Listen1Last := SubStr(Listen1, 21)
If (Listen1State = "ffff") {
	Listen1Change := Listen1First . "0000" . Listen1Last
	Listen1Length := StrLen(Listen1)
	Listen1ChangeLength := StrLen(Listen1Change)
	If (Listen1Length != Listen1ChangeLength) {
		MsgBox, "Lengths don't match."
		return
	}
	RegWrite,REG_BINARY,HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{d0649ed1-77fc-4bd5-a5f6-cf5600c5136f}\Properties,{24dbb0fc-9311-4b3d-9cf0-18ff155639d4}`,1,%Listen1Change%
}
Else If (Listen1State = "0000") {
	Listen1Change := Listen1First . "ffff" . Listen1Last
	Listen1Length := StrLen(Listen1)
	Listen1ChangeLength := StrLen(Listen1Change)
	If (Listen1Length != Listen1ChangeLength) {
		MsgBox, "Lengths don't match."
		return
	}
	RegWrite,REG_BINARY,HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{d0649ed1-77fc-4bd5-a5f6-cf5600c5136f}\Properties,{24dbb0fc-9311-4b3d-9cf0-18ff155639d4}`,1,%Listen1Change%
}
Else {
	MsgBox, "What is cheese?! `n(idk what happened xd)"
}
return
Last edited by XShayanX on 13 Sep 2019, 07:24, edited 1 time in total.
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 16:35

Wait is it possible to write a variable to a registry value?

Code: Select all

RegWrite,REG_BINARY,HKLM,SOFTWARE\...\Properties,{24dbb0fc-9311-4b3d-9cf0-18ff155639d4}`,1,%Listen1Change%
ilhom
Posts: 52
Joined: 19 Aug 2019, 17:58

Re: Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 16:47

XShayanX wrote:
12 Sep 2019, 16:35
Wait is it possible to write a variable to a registry value?

Code: Select all

RegWrite,REG_BINARY,HKLM,SOFTWARE\...\Properties,{24dbb0fc-9311-4b3d-9cf0-18ff155639d4}`,1,%Listen1Change%
Refer to this:
https://www.autohotkey.com/docs/commands/RegWrite.htm
RegWrite, ValueType, KeyName , ValueName, Value
Here is what you're doing
ValueType = REG_BINARY
Keyname = HKLM
ValueName = SOFTWARE\...\Properties
Value = {24dbb0fc-9311-4b3d-9cf0-18ff155639d4}`,1
Which means your variable isn't assigned to anything.


It looks like there is an extra comma between HKLM and the path. Try replacing it with a \ like so:

Code: Select all

RegWrite,REG_BINARY,HKLM\SOFTWARE\...\Properties,{24dbb0fc-9311-4b3d-9cf0-18ff155639d4}`,1,%Listen1Change%
Edit: Looks like you did the same thing with RegRead.
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 17:05

I was using the old syntax: RegWrite, ValueType, RootKey, SubKey , ValueName, Value
Regardless, I used the new syntax as you suggested but to no avail.
I check the registry value, and it still does not change after I press my hotkey.
At this point I'm really doubting regwrite supports %variables%
ilhom
Posts: 52
Joined: 19 Aug 2019, 17:58

Re: Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 17:25

XShayanX wrote:
12 Sep 2019, 17:05
I was using the old syntax: RegWrite, ValueType, RootKey, SubKey , ValueName, Value
Regardless, I used the new syntax as you suggested but to no avail.
I check the registry value, and it still does not change after I press my hotkey.
At this point I'm really doubting regwrite supports %variables%
Try adding msgbox %Listen1Change% prior to the RegWrite and see if it's a valid value.
Another test is to create a test variable with a static value that you know is correct and insert that in RegWrite
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 17:26

All values are correct :)

Code: Select all

Listen1[24 of 63]: 0B0000000100000000000000
Listen1Change[24 of 63]: 0B00000001000000ffff0000
Listen1ChangeLength[2 of 3]: 24
Listen1First[16 of 63]: 0B00000001000000
Listen1Last[4 of 7]: 0000
Listen1Length[2 of 3]: 24
Listen1State[4 of 7]: 0000
ilhom
Posts: 52
Joined: 19 Aug 2019, 17:58

Re: Registry Key Contains Comma - How To Escape It?

12 Sep 2019, 18:01

Okay, what if you copy the output from the msgbox and paste it as the value for the last parameter in RegWrite and RegRead? If that works, then I would imagine you would be correct about it variables being problematic in the function.
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Registry Key Contains Comma - How To Escape It?

13 Sep 2019, 06:39

Good thinking!
I tried what you said, it didn't write it to registry...
I wonder what's wrong..
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Registry Key Contains Comma - How To Escape It?

13 Sep 2019, 07:24

Sounds like there's bug with RegWrite in writing to HKLM:
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=62582
I don't know what to do now...
I have tried running the script with UAC access, as admin, converted it to exe and ran it as admin but all to no avail.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Registry Key Contains Comma - How To Escape It?

13 Sep 2019, 08:29

I don't think there's a bug. IMO, you need (at least) admin rights to write to the key. You might want to try the following:

Code: Select all

#NoEnv
RegKey := "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{d0649ed1-77fc-4bd5-a5f6-cf5600c5136f}\Properties"
RegVal := "{24dbb0fc-9311-4b3d-9cf0-18ff155639d4},1"
RegRead, Listen1, %RegKey%, %RegVal%
If (ErrorLevel) {
   MsgBox, 16, Error!, Error when trying to read the registry: %A_LastError%
   ExitApp
}
RegWrite, REG_BINARY, %RegKey%, %RegVal%, %Listen1%
If (ErrorLevel) {
   MsgBox, 16, Error!, Error when trying to write the registry: %A_LastError%
   ExitApp
}
MsgBox, 0, Success, All right!
ExitApp
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Registry Key Contains Comma - How To Escape It?

13 Sep 2019, 10:34

Thanks so much for the code.
I remember after I ran the hotkey, I double clicked on script icon on the status bar and from "Variables and their contents" I checked ErrorLevel, it was 0 but after I tried your code, I found out that ErrorCode is 5 (something must have interfered that my ErrorLevel was 0), and from Microsoft's Doc: https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
ERROR_ACCESS_DENIED
5 (0x5)
Access is denied.
As I said, I tried running the script normally, as admin and with UI Access even before this, but I did again, and I get ErrorLevel 5 for all of them:
I even tried converting the script to exe and then run it as admin, but no.. it still didn't work.
Image
Image
ilhom
Posts: 52
Joined: 19 Aug 2019, 17:58

Re: Registry Key Contains Comma - How To Escape It?

13 Sep 2019, 10:41

What if you open up regedit and go to the value and try to change it there? That could narrow down if it's a permission issue with the account/the value is locked, or with ahk making the edit.

Here is something that could help:
https://www.howtogeek.com/262464/how-to-gain-full-permissions-to-edit-protected-registry-keys/
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Registry Key Contains Comma - How To Escape It?

13 Sep 2019, 10:51

I have already tried that, I can modify and rename the values and keys without an issue with RegEdit, and I can export and apply *.reg files no problem.

BTW, I have a couple of other hotkeys in my script which use RegWrite to write to HKCU and HKU, and they work without an issue :)

Just right now I also prepended this script of mine with this:

Code: Select all

if not A_IsAdmin
Run *RunAs "%A_ScriptFullPath%"
Which makes sure my script is running as Admin.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: iamMG and 118 guests