# Formatting a drive from C++



## jimboa (Jul 3, 2008)

I have a need to format a multi-partitioned hard drive from C++ code on an XP system. None of the IOCTL type calls seem to fit the bill from XP. I can create the partitions but I can't format them. Is there something I'm missing. If Windows can do it via the format command why can't I do it from code?

Thanks.


----------



## lotuseclat79 (Sep 12, 2003)

Hi jimboa,

Let's understand some context of what you are trying to do here first.

You are booted up in a WinXP system running a C++ compiler writing system code that has the task of creating and formatting a partition on the disk.

So far, you have created a partition with your C++ code.

As I understand your question - it is: How do I format a partition?

Q: Are you running your code from a SysAdmin account?

-- Tom


----------



## jimboa (Jul 3, 2008)

The application is run under an account that is part of the Administrators group. It is fully privileged. Ultimately, the application will run as a service. 

One of the many things this application is called on to do is create 4 partitions on a hard drive then format the partitions as FAT32 drives (not NTFS). I have identified IOCTL calls to format a floppy but the only calls I can find to format a hard drive are only available if you are running Server 2003; we are limited to Windows/XP.

J.


----------



## pvc_ (Feb 18, 2008)

This approach may seem kindda funny, but it may actually work. If it's a console application, you might be able to use system("format") or perhaps use a bat file.


----------



## jimboa (Jul 3, 2008)

I don't know about 'funny' but it is a workaround. We have coded in a shell out to a batch file (we thought of that too) but we would prefer to do the format in code if at all possible.

J.


----------



## lotuseclat79 (Sep 12, 2003)

Hi jimboa,

It sounds like you may have to either add the ioctl code to the WinXP driver, or possibly get the Resource Kit for Server 2003 from the MS website.

-- Tom


----------

