Disk operations in Windows-Thoughts on formatting partitions

Source: Internet
Author: User
Original Works are allowed to be reprinted. During reprinting, please mark the article in hyperlink form
Original source, author information, and this statement. Otherwise, legal liability will be held. Http://cutebunny.blog.51cto.com/301216/625762

Formatting partitions is a common operation in our opinion. You can click twice to solve the problem, but it is not easy to implement it in the program. Some people may say that it is not good to directly call the format command, but the system command contains the problem described in Section 1 http://cutebunny.blog.51cto.com/301216/624027.

I have found three methods: 1. Windows API shformatdrive. The function prototype is DWORD shformatdrive (hwnd, uint drive, uint fmtid, uint options). The drive parameter is the partition to be formatted and starts counting from 0. 0 represents a:, 2 represents C:, and so on. For other parameters, see msdn. When you call this function, a dialog box that we are very familiar with is displayed. You can right-click it to format it.

The call method is simple:

Shformatdrive (0, 8, shfmt_id_default, shfmt_opt_full );

Unfortunately, this API cannot automatically start formatting. In any case, you must manually click Start ". Depressed, some people suggest you set up a timer and simulate enter again. After formatting, enter again. It works in principle, but it seems to be a bit nondescribable. 2. Using the undisclosed formatex function in fmifs. dll, a big guy named Mark russinovich wrote the specific code. I haven't taken the time to tune it for your reference. For more information about the code, see the attachment. Someone seems to have succeeded, please refer to the http://forum.sysinternals.com/creating-partitions-on-xp_topic3029.html 3. Format command this is no way, the Code is as follows, very simple, not much explanation. /*************************************** **************************************** Function: * input: disk, disk name * output: N/A * return: succeed, 0 * fail, 1 *************************************** ***************************************/ DWORD formatvolume (char letter) {DWORD ret; char cmd [64]; sprintf (CMD, "format % C:/Fs: NTFS/Q/Y", letter); ret = (DWORD) system (CMD); return ret ;} SummaryThe discussion on disk operation programming in Windows has come to an end. Finally, let's summarize all the examples we have listed above. DWORD getallpresentdisks (DWORD ** disks); // all physical disk numbers in the query system DWORD getsystemdiskphysicalnumber (void ); // obtain the physical disk number DWORD getphysicaldrivefrompartitionletter (char letter) of the operating system. // query the physical disk number DWORD getdrivegeometry (const char * disk, disk_geometry * PDG) based on the Logical Partition Number ); // query the disk physical information DWORD getdiskdrivelayout (const char * disk, drive_layout_information_ex * drivelayout); // query the disk partition information DWORD destroydisk (DWORD disk); // Delete the disk partition table DWORD cr Eatedisk (DWORD disk, word partnum); // initialize the disk and create a partition DWORD getpartitionletterfromphysicaldrive (DWORD pdrivenumber, char ** letters ); // query all the DWORD formatvolume (char letter) partitions on a physical disk, be careful when debugging. Of course, do not use it to do bad things.

 

 

This article is from the "bunny Technology Workshop" blog, please be sure to keep this source http://cutebunny.blog.51cto.com/301216/625762

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.