首页 > 代码库 > 修改注册表~使自启动
修改注册表~使自启动
【转自互联网】
1 #include <windows.h> 2 #include <stdio.h> 3 #pragma comment(lib,"Advapi32.lib") 4 void CreateStringReg(HKEY hRoot,char *szSubKey,char* ValueName,char *Data) 5 { 6 HKEY hKey; 7 //打开注册表键,不存在则创建它 8 long lRet=RegCreateKeyEx(hRoot,szSubKey,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,NULL); 9 if (lRet!=ERROR_SUCCESS) 10 { 11 printf("error no RegCreateKeyEx %s\n", szSubKey); 12 return ; 13 } 14 //修改注册表键值,没有则创建它 15 lRet=RegSetValueEx(hKey,ValueName,0,REG_SZ,(BYTE*)Data,strlen(Data)); 16 if (lRet!=ERROR_SUCCESS) 17 { 18 printf("error no RegSetValueEx %s\n", ValueName); 19 return ; 20 } 21 RegCloseKey(hKey); 22 } 23 24 int autorun() 25 { 26 char SelfFile[MAX_PATH]; 27 char SystemPath[512]; 28 //得到系统目录路径 29 GetSystemDirectory(SystemPath,sizeof(SystemPath)); 30 strcat_s(SystemPath,"\\explorer.exe"); 31 //得到自身程序路径 32 GetModuleFileName (NULL, SelfFile, MAX_PATH); 33 //复制文件 34 if(!CopyFile(SelfFile,SystemPath,true)) 35 return 0; 36 //写入注册表 37 CreateStringReg(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows","load",SystemPath); 38 return 0; 39 } 40 int main(int argc, char* argv[]) 41 { 42 autorun(); 43 return 0; 44 }
修改注册表~使自启动
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。