講授C++編程中Address-of運算符&的感化及用法。本站提示廣大學習愛好者:(講授C++編程中Address-of運算符&的感化及用法)文章只能為提供參考,不一定能成為您想要的結果。以下是講授C++編程中Address-of運算符&的感化及用法正文
法式比擬簡略,用到了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;
}