杂记--注册表

来源:互联网 发布:淘宝一键复制有违规吗 编辑:程序博客网 时间:2024/04/30 09:32
/************************************************************************//* 新建一个键,让程序在开机时自启动*//************************************************************************/CString temp="E:\\工作相关资料\\文件辅助\\WorkHelp.exe";int len=temp.GetLength();LPBYTE lpb = new BYTE[len];for(int j=0;j<len;j++){lpb[j]=temp[j];}lpb[j]=0;HKEY hKey;LPCTSTR data_Set="Software\\Microsoft\\Windows\\CurrentVersion\\Run";::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set,0,KEY_WRITE,&hKey);::RegSetValueEx(hKey,_T("workHelp"),NULL,REG_SZ,lpb,len);::RegCloseKey(hKey);



/************************************************************************//* 删除一个键*//************************************************************************/HKEY hKey;LPCTSTR data_Set="Software\\Microsoft\\Windows\\CurrentVersion\\Run";::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set,0,KEY_WRITE,&hKey);::RegDeleteValue(hKey,LPCTSTR("workHelp"));::RegCloseKey(hKey);