Porady: wpisywanie danych do rejestru systemu Windows (C++/CLI)
Następujący kod w przykładzie wykorzystano CurrentUser klawisz, aby utworzyć wystąpienie zapisywalny RegistryKey klasy odpowiadające Software klucz.CreateSubKey Metoda jest następnie używana do tworzenia nowego klucza i dodać do par klucz/wartość.
Przykład
Kod
// 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;
}
Uwagi
.NET Framework umożliwia dostęp do rejestru z Registry i RegistryKey klas, które są zdefiniowane w Microsoft.Win32 obszaru nazw.Rejestru klasy jest kontenerem dla wystąpień statycznych RegistryKey klasy.Każde wystąpienie reprezentuje węzła głównego rejestru.The instances are ClassesRoot, CurrentConfig, CurrentUser, LocalMachine, and Users.
Zobacz też
Koncepcje
Porady: odczytywanie danych z rejestru systemu Windows (C++/CLI)