Registry editing
I'm having trouble creating the code for a button to change a couple of registry keys. I've searched google for hours and hours now, but all the code I can find about registry editing doesn't work in my version (2005 beta 1). I can't even get the code from MSDN to work 
So my question is simple (I hope): Let's say I want that button to change the value from Username in the map HKEY_CURRENT_USER\Software\Blasoft\3dgame\ to Savarage, how would i do that
Thnx!
Registry editing
SteveRadich-BitShop.Com
SetValue( "BinaryValue", gcnew array<Byte>{10,43,44,45,14,255}, RegistryValueKind::Binary );
and guess what: it doesn't work. Believe me, I've tried a couple of things already and nothing works. In fact, everything i get of the msdn site doesn't work
I guess it has something to do with the fact I've got c++/CLI, but there's almost no info on that. So I'm asking for your help one last time. How do i get binary values into the registry Or do you know where i can find working code for c++/CLI
Ken Levy
larr
Registry::SetValue(keyName,
"Username", "Scamp");Registry::SetValue(keyName, "Password", gcnew array<Byte>{ 0x01, 0x02, 0x04 });
The CLR automatically works out that the second value is a binary value
Nucx
Some points:
1) The Beta-2 compiler does not seem to support:
string + string + string
So try the following:
String^ keyName = String::Concat(String::Concat(userRoot, "\\"), subKey);
Or the even the much simpler:
String^ keyName = "HKEY_CURRENT_USER\\FamilyGames\\MyNewPuppy";
2) To access the Registry class you need to add:
using namespace Microsoft::Win32;
at the top of the program: apologies for missing this before.
3) As this is a CLR program you no longer need to include windows.h or tchar.h
Madhu Ponduru ----MSFT
Thnx for your quick reply! I tried your code, but i got an error: there's no windows.h file. When i don't include it i get all these errors:
error C2065: 'LPCTSTR' : undeclared identifier
error C2146: syntax error : missing ')' before identifier 'pNewName'
error C2182: 'ChangeName' : illegal use of type 'void'
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2065: 'HKEY' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'hKey'
error C2065: 'hKey' : undeclared identifier
error C2065: 'HKEY_CURRENT_USER' : undeclared identifier
error C3861: 'RegOpenKey': identifier not found
error C2065: 'REG_SZ' : undeclared identifier
error C2065: 'pNewName' : undeclared identifier
error C3861: 'RegSetValue': identifier not found
error C3861: 'RegCloseKey': identifier not found
Is this because of the missing windows.h file or is there another problem
Can you please copy the code of your windows.h here, so I can make one myself and try it again, maby it works then.
Lol, this is exactly the same like all the other code I tried. I compile and it gives a lot of errors. Thnx anyway :)
muga
error C2601: 'ChangeName' : local function definitions are illegal
Any idea how to fix this
Kevin MacDonald
private: System::Void startbtn_Click(System::Object^ sender, System::EventArgs^ e)
{
void ChangeName(LPCTSTR pNewName){
HKEY hKey;
RegOpenKey(HKEY_CURRENT_USER, _T("Software\\thrixxx\\3DSexVilla"), &hKey);
RegSetValue(hKey, _T("Username"), REG_SZ, pNewName, _tcslen(pNewName));
RegCloseKey(hKey);
}
}
I'm almost embaressed to ask, but how do i make this work then Obviously deleting the void changename(lpctstr pnewname) part and deleting the { & } doesn't work cause then pNewName is undeclared. So how do I declare it
I just want to be able to write very small dialog based apps, but as you can see even working with the registry is too hard for me.
Thnx!
Yuval Rakavy
Ah: so you're working with C++/CLI - that's different. There's an easier way to do this: forget my previous suggestion. I presume your small application will have a text box into which the user can type the new name and then they will click on a button and the application updated the registry: correct If so then I would do something like the following:
void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if (textBox1->Text != nullptr) {
String^ userRoot = "HKEY_CURRENT_USER";
String^ subkey = "FamilyGames\\MyNewPuppy";
String^ keyName = userRoot + "\\" + subkey;
try {
Registry::SetValue(keyName, "Username", textBox1->Text);
}
catch (Exception^ e) {
// Handle any exceptions
Console::WriteLine(e);
}
}
}
musichenryviolin
It looks like you have pasted my whole code-snippet inside another function. This means that to the compiler it looks like ChangeName is a nested inside of another function: this is illegal in C++. If you just want the body of my function then get ride of the function declaration part.
Note: it is very rarely you can take some code posted on a forum and just paste it into your project and expect it to work. In many cases you will need to "adapt" to code to your own specific needs.
vikasamin
http://msdn.microsoft.com/library/default.asp url=/library/en-us/sysinfo/base/registry.asp
The code below is pretty much what I would do. Note: error checking is removed for brevity:
#include
<windows.h>#include <tchar.h>
void
ChangeName(LPCTSTR pNewName){
HKEY hKey;
RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Blasoft\\3dgame"), &hKey);
RegSetValue(hKey, _T("Username"), REG_SZ, pNewName, _tcslen(pNewName));
RegCloseKey(hKey);
}
BillTodd
From the fact that you are missing windows.h I am going to assume that you are using the Express Edition of Visual C++. If this is indeed the case then this edition of Visual C++ does not include the Platform SDK and you need to download this separately. Here is a link to the MSDN site that explains how:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/sdkintro/sdkintro/devdoc_platform_software_development_kit_start_page.asp
my name is KN
error C2845: 'System::String ^' : pointer arithmetic not allowed on this type
cerror C2653: 'Registry' : is not a class or namespace name
error C3861: 'SetValue': identifier not found
I have the platform SDK installed and have included the windows.h and tchar.h files.
So let me tell you exactly what my app will do (If i'll ever get it working). I'm very lazy, and i have a game where you've got to log in every time you wanna play. I don't want to type in my login and password every time, so I've tried to find out what happened with it. Everytime I press the login button, the values Username and Password are filled in the registry. When i exit the game they are emptied. So i want to make some sort of loader so the values are automatically set when i press the start button and i also want that start button to acually start the game. Btw: this is my edited code ( I've deleted the whole error checking part, cause i don't need it) :
private
: System::Void startbtn_Click(System::Object^ sender, System::EventArgs^ e){
String^ userRoot = "HKEY_CURRENT_USER";
String^ subkey = "FamilyGames\\MyNewPuppy";
String^ keyName = userRoot + "\\" + subkey;
Registry::SetValue(keyName, "Username", "Savarage");
}
Theeran
EDIT: Can you please show me how to add binary values, cause the password for the game is a binary value. I can't seem to get it working. Thnx.