WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Floppy and CD Drives

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Format a Floppy Drive

Keywords: format.exe   

Question:

How do I use WinBatch to format a floppy drive?

Answer:

WinBatch doesn't have any functions to format a drive. However here are two possiblities:

  1. You can automate the control panel applet, to format the floppy.
    Run("rundll32.exe", "shell32.dll,SHFormatDrive")
    SendKeysto("Format","!s")
    

  2. Or you can to use the DOS 'format' command to do that.

    The /autotest parameter for format is undocumented and runs format to work without asking for parameters.

    Therefore:

            run(environment("COMPSEC"),"/c format a: /autotest")
    
    will do a format of a: without asking any questions and close the Dos window upon completion. You may add any other parameters (such as /u, /s, /v:LABELNAME) as you wish. For example:
            Message("Format a:", "Put a diskette into the A: drive and press OK")
            runwait(environment("COMPSEC"),"/c format a: /u /autotest")
    
    will format without you having to answer the Dos questions such as Label name, and Do you want to format another Y/N

    This undocumented feature is missing from the WinNT format.

    For more on the FORMAT command see: http://www.microsoft.com/technet/archive/msdos/comm4.mspx

    Alternatively, the command will look something like this:

            runwait("command.com", "/c format a: < resp")
    
    where "resp" is a response file that you created and have in your C:\WINDOWS directory. This file automatically answers the yes/no questions in the format command. (Cautionary note: Test this carefully before you mass distribute it!!) The "resp" file would have the following contents:
    y
    n
    
    The "y" answers yes, and the "n" answers no. Make sure you have a carriage return after the final "n" in your response file.

    OK, so that's the basic idea. The trouble is that the DOS Format window will not automatically close when the format finishes, so you need to take this a step further.

    Create a DOS batch file, with the format command and parameters in it:

    rem MYFORMAT.BAT
    format a: < resp
    
    and make a Shortcut or PIF file named MYFORMAT.PIF that has the option, "Close Window on Exit" selected. Put the MYFORMAT.PIF file in the same directory as the MYFORMAT.BAT file, so that Windows will find it.

    Now change the runwait statement to run the PIF file:

            runwait("MYFORMAT.PIF", "")
    
    When the PIF file is launched, it will transfer control to MYFORMAT.BAT, and when the format is finished, the window will go away.

Article ID:   W13249
Filename:   Format a Floppy Drive.txt
File Created: 2004:09:14:10:49:00
Last Updated: 2004:09:14:10:49:00