1. 程式人生 > >110.文件搜索,系統大小獲取,以及病毒行為

110.文件搜索,系統大小獲取,以及病毒行為

以及 pac copy span style emd pau 獲取系統路徑 行為

  • 拷貝文件
     1 //拷貝文件
     2 void copy()
     3 {
     4     //自身路徑
     5     char selfpath[256] = { 0 };
     6     //Windows路徑
     7     char windowpath[256] = { 0 };
     8     //系統路徑
     9     char systempath[256] = { 0 };
    10 
    11     //獲取自身路徑
    12     GetModuleFileNameA(NULL, selfpath, 256);
    13     //獲取Windows路徑
    14     GetWindowsDirectoryA(windowpath, 256
    ); 15 //獲取系統路徑 16 GetSystemDirectoryA(systempath, 256); 17 strcat(windowpath, "\\test.exe"); 18 strcat(systempath, "\\test.exe"); 19 //輸出目錄 20 printf("%s\n", selfpath); 21 printf("%s\n", windowpath); 22 printf("%s\n", systempath); 23 //拷貝函數 24 CopyFileA(selfpath, windowpath, FALSE);
    25 }

  • 遍歷所有磁盤信息
     1 //遍歷所有磁盤信息
     2 void find_all()
     3 {
     4     char szbuf[100] = { 0 };
     5     //載入磁盤信息
     6     GetLogicalDriveStrings(100, szbuf);
     7     char *p = szbuf;
     8     while (*p != \0)
     9     {
    10         printf("%s\n", p);
    11         getspace(p);
    12         p += strlen(p) + 1;
    13     }
    14 }

  • 獲取磁盤大小
     1
    //獲取磁盤大小 2 int getspace(char *pstr) 3 { 4 //剩余空間 可用空間 總大小 5 ULARGE_INTEGER dwl, dwfree, dwtol; 6 char szsize[128] = { 0 }; 7 double size = 0; 8 GetDiskFreeSpaceEx(pstr, &dwl, &dwtol, &dwfree); 9 size = dwtol.QuadPart / 1024.0 / 1024 / 1204;//GB 10 printf("總大小:%f GB\n", size); 11 size = dwl.QuadPart / 1024.0 / 1024 / 1204;//GB 12 printf("剩余空間:%f GB\n", size); 13 size = dwfree.QuadPart / 1024.0 / 1024 / 1204;//GB 14 printf("可用空間:%f GB\n", size); 15 }

完整代碼

 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include <Windows.h>
 3 #include <stdio.h>
 4 #include <stdlib.h>
 5 //獲取磁盤大小
 6 int getspace(char *pstr)
 7 {
 8     //剩余空間 可用空間  總大小
 9     ULARGE_INTEGER dwl, dwfree, dwtol;
10     char szsize[128] = { 0 };
11     double size = 0;
12     GetDiskFreeSpaceEx(pstr, &dwl, &dwtol, &dwfree);
13     size = dwtol.QuadPart / 1024.0 / 1024 / 1204;//GB
14     printf("總大小:%f GB\n", size);
15     size = dwl.QuadPart / 1024.0 / 1024 / 1204;//GB
16     printf("剩余空間:%f GB\n", size);
17     size = dwfree.QuadPart / 1024.0 / 1024 / 1204;//GB
18     printf("可用空間:%f GB\n", size);
19 }
20 
21 //遍歷所有磁盤信息
22 void find_all()
23 {
24     char szbuf[100] = { 0 };
25     //載入磁盤信息
26     GetLogicalDriveStrings(100, szbuf);
27     char *p = szbuf;
28     while (*p != \0)
29     {
30         printf("%s\n", p);
31         getspace(p);
32         p += strlen(p) + 1;
33     }
34 }
35 
36 //拷貝文件
37 void copy()
38 {
39     //自身路徑
40     char selfpath[256] = { 0 };
41     //Windows路徑
42     char windowpath[256] = { 0 };
43     //系統路徑
44     char systempath[256] = { 0 };
45 
46     //獲取自身路徑
47     GetModuleFileNameA(NULL, selfpath, 256);
48     //獲取Windows路徑
49     GetWindowsDirectoryA(windowpath, 256);
50     //獲取系統路徑
51     GetSystemDirectoryA(systempath, 256);
52     strcat(windowpath, "\\test.exe");
53     strcat(systempath, "\\test.exe");
54     //輸出目錄
55     printf("%s\n", selfpath);
56     printf("%s\n", windowpath);
57     printf("%s\n", systempath);
58     //拷貝函數
59     CopyFileA(selfpath, windowpath, FALSE);
60 }
61 
62 void main()
63 {
64     find_all();
65     system("pause");
66     
67     system("pause");
68 }

110.文件搜索,系統大小獲取,以及病毒行為