1#include <iostream>2#include <windows.h>3 using namespacestd;4 5 intMain ()6 {7 HKEY HKEY;8 HKEY hKEY1;9 Ten Char*regsz ="This is s test!"; OneDWORD Regdword = -; ABYTE regbin[4] = {0x54,0x65,0x73,0x74}; - - //to open the registry in write mode the if(Error_success = = RegOpenKeyEx (HKEY_LOCAL_MACHINE,"SYSTEM",0, Key_set_value, &HKEY)) - { - //Write Registry sub key Test - if(Error_success = = RegCreateKey (HKEY,"Test", &hKEY1)) + { - //write the REG_SZ type key value under sub-key Test Testregsz + if(Error_success = = RegSetValueEx (hKEY1,"Testregsz",0, REG_SZ, (byte*) Regsz, strlen (REGSZ) +1)) A { at //write the REG_DWORD type key value under sub-key Test Testregdword - if(Error_success = = RegSetValueEx (hKEY1,"Testregdword",0, REG_DWORD, (byte*) ®dword,sizeof(DWORD))) - { - //write the REG_BINARY type key value under sub-key Test Testregbin - if(Error_success = = RegSetValueEx (hKEY1,"Testregbin",0, REG_BINARY, Regbin,sizeof(Regbin))) - { inMessageBox (NULL,"Write registry key value succeeded! ","Tips:", mb_iconexclamation); - } to } + } - Else the { *MessageBox (NULL,"failed to write registry key value! ","Tips:", mb_iconerror); $ }Panax Notoginseng } - Else the { +MessageBox (NULL,"failed to write registry subkey! ","Tips:", mb_iconerror); A } the + RegCloseKey (hKEY1); - } $ Else $ { -MessageBox (NULL,"failed to open the registry! ","Tips:", mb_iconerror); - } the RegCloseKey (HKEY); - return 0;Wuyi}
C + + Write registry