We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How To Format A Floppy Disk Through Delphi 3

k6__
k6__ asked
on
Medium Priority
374 Views
Last Modified: 2010-04-03
Any Ideas How To Format a floppy Disk without showing
any dialog ?
Comment
Watch Question

There is an API hidden away in Shell32.dll called SHFormatDrive,
 this brings up the standard format removable drive dialog.

{implementation section}


const
        SHFMT_ID_DEFAULT      = $FFFF;  // Formating options
        SHFMT_OPT_QUICKFORMAT = $0000;
        SHFMT_OPT_FULL        = $0001;
        SHFMT_OPT_SYSONLY     = $0002;  // Error codes
        SHFMT_ERROR           = $FFFFFFFF;
        SHFMT_CANCEL          = $FFFFFFFE;
        SHFMT_NOFORMAT        = $FFFFFFFD;

function SHFormatDrive(Handle: HWND; Drive, ID, Options: Word): LongInt;
        stdcall; external 'shell32.dll' name 'SHFormatDrive'

procedure TForm1.btnFormatDiskClick(Sender: TObject);
var
  retCode: LongInt;

begin
 retCode:= SHFormatDrive(Handle, 0, SHFMT_ID_DEFAULT,SHFMT_OPT_QUICKFORMAT);
  if retCode < 0 then
      ShowMessage('Could not format drive');
end;

end.

You will need to contact the Dialog somehow, evt. via WinAPI, if you dont get it working or get another answer here, mail me and ill try code it for you..  brainware@software.dk


Commented:
k6__

Why not use the DeviceIOControl API call and pass the parameter IOCTL_DISK_FORMAT_TRACKS etc. There are a lot more options as well like segtting the volume label etc...

The IOCTL_DISK_FORMAT_TRACKS DeviceIoControl operation formats a specified, contiguous set of tracks on a disk.

Later
BoRiS

Author

Commented:
i said i don't want to show any dialog.. so IOCTL_DISK_FORMAT_TRACKS function can do it ? an example ? =)

thanx =)

Author

Commented:


Commented:
k6__

If you wanted code example all you had to do is ask(not reject the answer), for future
reference ask for source code examples in the first question...

Anyway enough of that now (GEEZ)

I'll give you an example, let me just check it out again...

Later
BoRIS

Author

Commented:
ermmh =| sorry ... i accidentally rejected it... =(
i thouht that i choose Acceptable .. =(
sorry again Boris

Commented:

Why not use the CreateProcess or WinExec to use the format program under c:\dos.
And by giving the SW_HIDE as a parameter to hide the window, and a text file to redirect to FORMAT program to respond to the prompts from the FORMAT command(like insert diskette, enter volume label...)


Author

Commented:
Nope ... i though of that but i don't want to call DOS through
my app =)

Thanx...

Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
Drop a component to the form, and call yourcomponent.execute
you will have no dialog opening.
I hope it helps.
Jeurk

Author

Commented:
jeurk thanx but i didn't want that.. i knew the SHFormatDrive
function of Shell32.dll but anyway somebody posted the answer
that i was looking through a win32s Function =)


Commented:
Hello,
So why did I earned the points ;) ?

Author

Commented:
your ean points cause i accidentally REJECTED =( the right
answer =(

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.