Search the Registry Class’ in help – lots of examples

using namespace Microsoft::Win32;

Help has good example for the registry class.

Read A Registry Value


	String ^VlcInstallPath;
	VlcInstallPath = Convert::ToString(Registry::GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\VideoLAN\\VLC", "InstallDir", ""));

Working Example Of Reading FTDI USB Chip entries in the Registry


//----- CHECK REGISTRY TO FIND MATCHING FDTI DEVICES AND ONLY INCLUDE THOSE COMM PORTS -----
//(We only show comm ports for our devices that are currently connected)
//This is the registry path we're interested in (taken from FTDI web site):-
//HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\FTDIBUS\VID_VID+PID_PID+Serial_Number\0000\DeviceParameters\PortName

//Retrieve all the subkeys for the specified key.
RegistryKey ^rkey = Registry::LocalMachine;
rkey = rkey->OpenSubKey(L"SYSTEM\\CurrentControlSet\\Enum\\FTDIBUS");
array<String^>^names = rkey->GetSubKeyNames();

for each (String^ name in names)
{
	//----- CHECK NEXT FTDI DEVICE IN THE REGISTRY -----
	//name = VID_VID+PID_PID+Serial_Number

	//Get Serial Number portion
	CharPosn = name->LastIndexOf("+");
	if (CharPosn >= 0)
	{
		SerialNumber = name->Substring(CharPosn + 1);	//Returns rest of string starting at character posn #
		SerialNumber = SerialNumber->Trim();

		if ((SerialNumber->Length == 9) && (SerialNumber->Contains("KPS")))
		{
			//THIS IS A LIBRA POWER SUPPLY - GET THE COMM PORT FIELD
			rkey = rkey->OpenSubKey(name);
			rkey = rkey->OpenSubKey(L"0000\\Device Parameters");
			Port = Convert::ToString(rkey->GetValue("PortName"));		//Will be COM1 etc

		}
	}

}
rkey->Close();

Writing To Registry

On Windows Vista access permission must be available to modify a registry value. If you are creating the registry entry you can specify that all users have access, but if not then you will often find that UAC will not allow access under Vista and above.
For an example see Serial Port>FTDI USB Devices > Setting Latency

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *