程序比較簡單,用到了C語言獲得自身路徑和系統(tǒng)路徑,修改注冊表項(xiàng)等,某些函數(shù)不理解可以查看MSDN
#include<stdio.h>#include<windows.h>char *GetFilename(char *p) //得到一個(gè)路徑的純文件名{ int x=strlen(p); char ch='//'; char *q=strrchr(p,ch); return q;}int main(){ char *filepath; char modlepath[256]; char syspath[256]; //打開酷狗應(yīng)用 filepath="C://Program^ Files//KuGou//KGMusic//KuGou.exe"; system(filepath); //將程序移動到系統(tǒng)目錄下 GetModuleFileName(0,modlepath,256); //獲得自身路徑 GetSystemDirectory(syspath,256); //得到系統(tǒng)路徑 int ret=CopyFile(modlepath,strcat(syspath,GetFilename(modlepath)),1);//復(fù)制,CopyFile的第二個(gè)參數(shù)是目標(biāo)文件名 if(ret) { printf("%s has been copyed to sys dir %s/n",modlepath,syspath); } else { printf("%s is exists",modlepath); } //程序添加開機(jī)自啟動 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); //設(shè)置鍵值 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;}
新聞熱點(diǎn)
疑難解答
圖片精選