C语言实现应用程序开机自启动(写进注册表)

来源:互联网 发布:ubuntu如何重置系统 编辑:程序博客网 时间:2024/05/22 06:18
#include <windows.h>#include <stdio.h>int main(){//找到系统的启动项 char *szSubKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";char *szModule ="C:\\Users\\hello\\AppData\\Local\\Temp\\test.exe";HKEY hKey;//打开注册表启动项 if(RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_ALL_ACCESS, &hKey)== ERROR_SUCCESS){//添加一个子Key,并设置值,"Mytest"并不一定是应用程序名字(不加后缀.exe) ,可以自己设置;RegSetValueEx(hKey, "Mytest", 0, REG_SZ, (BYTE *)szModule, strlen(szModule));//关闭注册表RegCloseKey(hKey);}else{return -1;}return 0;}

0 0
原创粉丝点击