#include "stdafx.h" #include "windows.h" #include "string.h" int _tmain(int argc, _TCHAR* argv[]) { HKEY hKey; //定义有关的hKey,在查询结束时要关闭。 LPCTSTR path = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; LONG return0=(::RegOpenKeyEx(HKEY_CURRENT_USER,path,0,KEY_ALL_ACCESS,&hKey)); if(return0!=ERROR_SUCCESS) { ::MessageBox(NULL, L"错误:无法打开有关的键!",NULL,MB_ICONERROR | MB_OK); return 1; }else { //RegSetValueEx(hKey, L"MSAWIN", 0, REG_SZ, (const BYTE *)path, strlen((const char *)(path)) ); RegDeleteValue(hKey, TEXT("MSAWIN")); } LPBYTE username_Get=new BYTE[80]; DWORD type_1=REG_SZ; DWORD cbData_1=80; LONG return1=::RegQueryValueEx(hKey,L"MSAWIN",NULL,&type_1,username_Get,&cbData_1); if(return1!=ERROR_SUCCESS) { ::MessageBox(NULL, L"错误:无法查询有关注册表信息!",NULL,MB_ICONERROR | MB_OK); return 1; }else { ::MessageBox(NULL, L"注册表注册成功!",NULL,MB_ICONERROR | MB_OK); } //程序结束前关闭已经打开的hKey RegCloseKey(hKey); return 0; }