Click here to Skip to main content
15,867,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
system("reg add HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\ /v TEST /t REG_SZ /d CPU Name");


I need this command executed in my c++ Project but it gives my following error while executing: Invalid Key Name becouse it doesnt understand where the key name beginns/ends becouse i cant use "" in there.

If someone could help me out it would be great

Sry for my any misspellings i am not native english.

What I have tried:

I Googled it but i still cant quite get it to work.
Posted
Updated 30-Jun-21 1:38am

Adding keys to the registry can make your system unusable, especially when not using the proper API calls. You should use Registry Functions - Win32 apps | Microsoft Docs[^], and only ever add to a keyname that you create inside HKEY_CURRENT_USER.
 
Share this answer
 
Comments
merano99 30-Jun-21 17:47pm    
To access HKLM (HKEY_LOCAL_MACHINE) you need admin rights, e.g. elevate your application using UAC. You can also allow access to the Key by editing the permissions on the relevant registry key.
Richard MacCutchan 1-Jul-21 4:07am    
Why are you telling me this?
Quote:
system("reg add HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\ /v TEST /t REG_SZ /d CPU Name");

The backslash is the escape character in C/C++ strings, and it must be escaped as well.
Replace every occurrence of \, in your string, with the sequence \\.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900