Invalid character in registry value

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
imjuzcy
Posts: 2
Joined: 03 Mar 2020, 15:12

Invalid character in registry value

19 Oct 2021, 08:02

I'm trying to use RegRead to read a registry value, but the value contains invalid character and AHK refuses to use the variable, complaining that it contains invalid character.

The code:

Code: Select all

Loop, Reg, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\kbdhid\Enum, KV
{
	if (A_LoopRegType = "REG_SZ")
	{
		RegRead, value
		MsgBox, , , %value%, 100
		if (%value% ~= "00001124-0000-1000-8000-00805f9b34fb")
		{
			MsgBox, , Title, Text, 5
			KeyboardConnected := true
		}
	}
}
Example value that gives error:
HID\{00001124-0000-1000-8000-00805f9b34fb}_VID&0002046d_PID&b342&Col01\8&3156b294&0&0000

The MsgBox line works, but the if (%value% ~= "00001124-0000-1000-8000-00805f9b34fb") line doesn't.

Is there anyway to remove the invalid characters so that AHK can use the variable?
Last edited by joedf on 19 Oct 2021, 09:03, edited 2 times in total.
Reason: [code] tags and inline [c]ode tags
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Invalid character in registry value

19 Oct 2021, 09:17

Although I have not tested this, in most cases, one would use an expression format such as the following.

Code: Select all

If (value ~= "00001124-0000-1000-8000-00805f9b34fb")
Explained: ExpressionsIf
User avatar
Spawnova
Posts: 554
Joined: 08 Jul 2015, 00:12
Contact:

Re: Invalid character in registry value

19 Oct 2021, 10:09

Also as far as I know ~= is not a proper syntax in AutoHotKey, you are looking for != instead
if (value != "00001124-0000-1000-8000-00805f9b34fb")

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mapcarter, Marium0505 and 373 guests