将程序复制到系统目录,设置开机自启动
2016-01-01 04:14
447 查看
程序比较简单,用到了C语言获得自身路径和系统路径,修改注册表项等,某些函数不理解可以查看MSDN
附-参考:
http://zhidao.baidu.com/link?url=9jIBTUUs-AvKkD2QZAxsdnxYAfTjnJxMfbqF3_lXd-g9NJJyyW6x-wI31kyWlRkRuT9TM4arYlJXmsc5VehPYa
#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; }
附-参考:
http://zhidao.baidu.com/link?url=9jIBTUUs-AvKkD2QZAxsdnxYAfTjnJxMfbqF3_lXd-g9NJJyyW6x-wI31kyWlRkRuT9TM4arYlJXmsc5VehPYa
相关文章推荐
- 理解Fragment生命周期
- Fragment间的通信
- Java设计模式——六大原则
- Android之greenDao的使用
- 黑马程序员——网络编程之TCP协议
- HDU2853-Assignment KM 限制边的交换
- 接口回调
- cocos2d-x学习笔记【一】创建自己的场景类
- 黑马程序员——网络编程之UDP协议
- -bash: fork: retry: Resource temporarily unavailable
- 在新的一年里,小娜伴我前行
- ISO/IEC 9899:2011 条款6.8.4——选择语句
- 医道官途
- Android子线程中更新UI的三种方法和获取message的两种方法总结
- HDU3435-A new Graph Game KM
- Android Studio开发项目中问题总结
- Gradlle 全解析(Android官方技术文档翻译)
- HDU3488-Tour KM
- 黑马程序员——正则表达式及模式与匹配器对象
- HDU1853-Cyclic Tour KM