国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C > 正文

C語言實現程序開機自啟動

2020-01-26 14:47:10
字體:
來源:轉載
供稿:網友

程序比較簡單,用到了C語言獲得自身路徑和系統路徑,修改注冊表項等,某些函數不理解可以查看MSDN

#include<stdio.h>#include<windows.h>char *GetFilename(char *p) //得到一個路徑的純文件名{  int x=strlen(p);  char ch='//';  char *q=strrchr(p,ch);  return q;}int main(){  char *filepath;  char modlepath[256];  char syspath[256];  //打開酷狗應用  filepath="C://Program^ Files//KuGou//KGMusic//KuGou.exe";   system(filepath);  //將程序移動到系統目錄下  GetModuleFileName(0,modlepath,256); //獲得自身路徑  GetSystemDirectory(syspath,256); //得到系統路徑  int ret=CopyFile(modlepath,strcat(syspath,GetFilename(modlepath)),1);//復制,CopyFile的第二個參數是目標文件名  if(ret)  {    printf("%s has been copyed to sys dir %s/n",modlepath,syspath);  }  else  {    printf("%s is exists",modlepath);  }  //程序添加開機自啟動  char regname[]="Software//Microsoft//Windows//CurrentVersion//Run";  HKEY hKey;  ret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hKey);    //打開注冊表鍵  ret=RegSetValueEx(hKey,"MyProm",0,REG_EXPAND_SZ,(unsigned char*)strcat(syspath,GetFilename(modlepath)),25); //設置鍵值  if(ret==0)  {    printf("succes to write run key./n");    RegCloseKey(hKey);  }  else  {    printf("failed to open regedit.%d/n",ret);    return 0;  }    return 0;}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 绵阳市| 道孚县| 肃宁县| 科尔| 安岳县| 蒙自县| 北海市| 绥江县| 卢氏县| 武威市| 吉林市| 辽宁省| 娄底市| 海阳市| 池州市| 阿克| 沂水县| 汶上县| 孝义市| 千阳县| 沙雅县| 紫云| 宝坻区| 蒙阴县| 聊城市| 许昌市| 望谟县| 兴安盟| 新绛县| 沁源县| 山阴县| 安岳县| 平潭县| 沙河市| 西吉县| 溧阳市| 大洼县| 南投市| 进贤县| 汉中市| 浦北县|