/////////////////////////////////////////////////////////////// // addkey.cpp - demonstrate adding key to registry // // ver 1.0 // // // // Jim Fawcett, CST 2-187, Syracuse Univ // // fawcett@ecs.syr.edu, (315) 443-3948 // // // // Modified from Win32 System Services, Marshall Brain, // // Prentice Hall, 1996 // /////////////////////////////////////////////////////////////// // Note: // // View result with regedit.exe (don't modify anything!) // // // /////////////////////////////////////////////////////////////// #include #include #include using namespace std; void main(int argc, char *argv[]) { cout << "\n Demonstrating Adding Key to Registry " << "\n ======================================\n"; LONG ret; HKEY keyHandle; DWORD disposition; // get key from command line char *key = argv[argc-1]; cout << "\n do you want to add the key:\n " << key << " ? "; char ch = _getche(); cout << "\n"; if(tolower(ch) == 'n') { return; } // // add a temporary key ret=RegCreateKeyEx( HKEY_CURRENT_USER, // add under this hive key, // key to add 0, // reserved NULL, // class string REG_OPTION_VOLATILE, // options flag KEY_ALL_ACCESS, // security access mask NULL, // security attributes &keyHandle, // place to save opened handle &disposition // place to save result ); if (ret != ERROR_SUCCESS) { cerr << "\n Unable to create key" << key << endl; return; } switch (disposition) { case REG_CREATED_NEW_KEY: cout << "\n New key " << key << " added to registry." << endl; break; case REG_OPENED_EXISTING_KEY: cout << "\n Existing key " << key << " opened." << endl; break; default: cout << "\n Key disposition unknown." << endl; } // close the new key ret=RegCloseKey(keyHandle); if (ret != ERROR_SUCCESS) { cerr << "\n Unable to close new key" << endl; return; } cout << "\n\n"; }