c++ 写注册表 并将exe添加到开机启动

来源:互联网 发布:富云软件科技有限公司 编辑:程序博客网 时间:2024/05/21 08:48
// CreateRegedit.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <string>#include <iostream>#include <windows.h>using namespace std;int _tmain(int argc, _TCHAR* argv[]){HKEY hPrimaryKey = HKEY_LOCAL_MACHINE;TCHAR *lpSubKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");HKEY hKey;DWORD dwDisposition = REG_OPENED_EXISTING_KEY;LONG lRet = RegCreateKeyEx(hPrimaryKey,lpSubKey,0,0,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&hKey,&dwDisposition);if (lRet != ERROR_SUCCESS){return 0;}//TCHAR TCHAR strFilePath[500];GetModuleFileName(0, strFilePath, 500);lRet = RegSetValueEx(hKey,_T("SelfRunDemo"),0,REG_SZ,(BYTE*)strFilePath,lstrlen(strFilePath)*sizeof(TCHAR));if (lRet == ERROR_SUCCESS){MessageBox(0, _T("love you forever"), _T("JW"),0);}RegCloseKey(hKey);return 0;}


2 0