C++设置开机启动

来源:互联网 发布:数据科学家 编辑:程序博客网 时间:2024/06/05 18:17
// ConsoleApplication3.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include <string>#include<windows.h>#include<iostream>#include <stdio.h>#include<cstring>using namespace std;int _tmain(int argc, _TCHAR* argv[]){HKEY   hKey;TCHAR strTemp[_MAX_PATH] = { 0 };//开机启动注册表路径TCHAR strAppName[MAX_PATH] = { 0 };//设置一个要写入的注册表名称TCHAR strAppPath[MAX_PATH] = { 0 };//要开机启动的exe路径和启动参数(如果有参数的话)      swprintf_s(strTemp, _T("%s"), "Software\\Microsoft\\Windows\\CurrentVersion\\Run");swprintf_s(strAppName, _T("%s"), "MyTestApp");swprintf_s(strAppPath, _T("%s"), "\"C:\\Program Files(x86)\\glireader\\科学阅读器\\Sciencereading.exe\" \"AutoStartTest\"");INT  retVal=RegCreateKey(HKEY_CURRENT_USER, strTemp, &hKey);retVal=RegSetValueEx(hKey, strAppName, 0, REG_SZ, (const BYTE*)strAppPath, (wcslen(strAppPath) + 1) * 2);RegCloseKey(hKey);return 0;}

原创粉丝点击