The following code example uses the
Example
В | ![]() |
---|---|
// registry_write.cpp // compile with: /clr using namespace System; using namespace Microsoft::Win32; int main() { // The second OpenSubKey argument indicates that // the subkey should be writable. RegistryKey^ rk; rk = Registry::CurrentUser->OpenSubKey("Software", true); if (!rk) { Console::WriteLine("Failed to open CurrentUser/Software key"); return -1; } RegistryKey^ nk = rk->CreateSubKey("NewRegKey"); if (!nk) { Console::WriteLine("Failed to create 'NewRegKey'"); return -1; } String^ newValue = "NewValue"; try { nk->SetValue("NewKey", newValue); nk->SetValue("NewKey2", 44); } catch (Exception^) { Console::WriteLine("Failed to set new values in 'NewRegKey'"); return -1; } Console::WriteLine("New key created."); Console::Write("Use REGEDIT.EXE to verify "); Console::WriteLine("'CURRENTUSER/Software/NewRegKey'\n"); return 0; } |
Remarks
You can use the .NET Framework to access the registry with the