Registry [C++/CLI]

I finally got my permissions working, it was a stupid error that didn't pop up in the build log. I need to be able to write my program to the registry to this path:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\<path_to_executable>
and add a new value "RUNASADMIN". How would I do this?
Like this:

1
2
3
4
5
6
7
8
9
const BYTE mydata[] = _T("RUNASADMIN");
	HKEY hKey;
	RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"), NULL, KEY_SET_VALUE, &hKey);
	if(RegSetValueEx(hKey, _T("PathToMyExecutable"), NULL, REG_SZ, mydata, sizeof(mydata)) == ERROR_SUCCESS){
		printf("%s", "Key created");
		} else {
			printf("%s, %d", "Key not created, error", GetLastError());
		}
	RegCloseKey(hKey);
I got some errors. What heading do I need, and this normal C++ or C++/CLI
This is winapi. In C/C++ you need windows.h and maybe tchar.h for the _T() macro. The functions are exported from advapi32.dll


In the future I suggest you to start learning yourself though MSDN documentation.
@ OP: Learning from MSDN is not as intimidating as it sounds, here's some stuff to get you started:

RegOpenKeyEx(): http://msdn.microsoft.com/en-us/library/ms724897(VS.85).aspx

RegSetValueEx(): http://msdn.microsoft.com/en-us/library/ms724923(VS.85).aspx

As you can probably see, the layout is pretty standardized within the site, and easy to read once you get the hang of it. I personally like the "Classic View" as it gives you the related functions and what not in the panel to the left of the main window but as usual on the internet YMMV.
I've used them some, but a lot of the stuff I don't get (yet). I'm about a year new to C++ and 5 months new to C++/CLI, and glad the syntax is better than the managed of the early 2000's.
This is the link that I found to write to the registry.
http://msdn.microsoft.com/en-us/library/bwt6b955.aspx

What you gave me, helped understand it better.
Does it really matter if I write the string value to Current Version, or could I make my own subkey and it still run with Admin privileges?
You dont need admin privileges to write in HKEY_CURRENT_USER.
The path in the topic that I posted give you Admin privileges. I was wondering if I created a different subfolder in the HKEY_Current_User and have the same attributes, if I could still have the admin privileges. And thanks, didn't know that you don't have to have admin privileges to write to HKEY_Current_USER
Topic archived. No new replies allowed.