简单的API应用

对于初学系统编程,了解下系统的API是必要的;

下面这个程序实现的是将自身程序复制到windows目录和系统目录;

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<windows.h>
 4 void copyself()
 5 {
 6     char selfpath[MAX_PATH]{0};
 7     char windowspath[MAX_PATH]{0};
 8     char systempath[MAX_PATH]{0};
 9     char tmppath[MAX_PATH]{0};
10     GetModuleFileName(NULL,selfpath,MAX_PATH);  //获取自身程序路径;
11     printf("self path is %s\n",selfpath);
12     GetWindowsDirectory(windowspath,MAX_PATH);  //获取windows路径;
13     printf("windows path is %s\n",windowspath);
14     GetSystemDirectory(systempath,MAX_PATH); // 获取系统路径;
15     printf("system path is %s\n",systempath);
16     strcat(windowspath,"\\test.exe");
17     strcat(systempath,"\\test.exe");
18     CopyFile(selfpath,windowspath,true); //复制自身到windows路径;
19     CopyFile(selfpath,systempath,true);  //复制自身到系统路径;
20     return ;
21 }
22 
23 int main()
24 {
25     copyself();
26     return 0;
27 }

 

posted on 2014-02-25 19:37  ~Love()  阅读(141)  评论(0编辑  收藏  举报

导航