zoukankan      html  css  js  c++  java
  • 110.文件搜索,系统大小获取,以及病毒行为

    • 拷贝文件
       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
      ", selfpath);
      21     printf("%s
      ", windowpath);
      22     printf("%s
      ", 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 != '')
       9     {
      10         printf("%s
      ", 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
      ", size);
      11     size = dwl.QuadPart / 1024.0 / 1024 / 1204;//GB
      12     printf("剩余空间:%f GB
      ", size);
      13     size = dwfree.QuadPart / 1024.0 / 1024 / 1204;//GB
      14     printf("可用空间:%f GB
      ", 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
    ", size);
    15     size = dwl.QuadPart / 1024.0 / 1024 / 1204;//GB
    16     printf("剩余空间:%f GB
    ", size);
    17     size = dwfree.QuadPart / 1024.0 / 1024 / 1204;//GB
    18     printf("可用空间:%f GB
    ", 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 != '')
    29     {
    30         printf("%s
    ", 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
    ", selfpath);
    56     printf("%s
    ", windowpath);
    57     printf("%s
    ", systempath);
    58     //拷贝函数
    59     CopyFileA(selfpath, windowpath, FALSE);
    60 }
    61 
    62 void main()
    63 {
    64     find_all();
    65     system("pause");
    66     
    67     system("pause");
    68 }
  • 相关阅读:
    Beta版本冲刺第二天
    项目冲刺-第十天
    项目冲刺-第五天
    用例图练习
    软件案例分析(微软必应词典客户端)
    第二次作业——结对项目之需求分析与原型模型设计
    git for windows 入门随笔
    软件工程的实践项目的自我目标
    Android的开发环境的发展演变
    我的软件工程实践的总结
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8504398.html
Copyright © 2011-2022 走看看