Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Formating a floppy disk
Message
From
11/09/2000 16:00:15
 
 
To
11/09/2000 05:13:13
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00410342
Message ID:
00415088
Views:
20
>>How to make that unattended/automatic format?
>>
>Hi Steve
>Try anything like that...
>Also you can make PIF file and run that.
>
>#DEFINE SW_HIDE 0
>#DEFINE SW_NORMAL 1
>
>Declare INTEGER WinExec IN WIN32API ;
> STRING lpCmdLine,;
> INTEGER nCmdShow
>
>lpCmdLine = "D:\\winntw\\system32\\format.com a:"
>
>? WinExec(@lpCmdLine, SW_NORMAL)
>
>WinExec must returm value more then 31 if success
>

Denis, someone also posted an API call that initiated the Windows Format dialog a couple of weeks ago; after noone bothered to post it in the FAQ, I posted the sample code to do this in the Windows API section to call SHFormatDrive(), provided via SHELL32.DLL (needs at least Shell32 v 4 or later). THis starts the Windows format dialog rahter than firing the command line format, and can be tested for success or failure. It requires interaction with the dialog to complete.

Calling the command line format unattended, directing the activity via sending keystrokes to the DOS box, while dangerous, can be done using the WSH Wscript.Shell object to direct keystrokes to the started format command. It relies on the standard title assigned to console apps started via the Wscript.Shell's RUN method:
oShell = CREATEOBJ('Wscript.Shell')
DECLARE Sleep IN WIN32API INTEGER dw_ms
oShell.Run('FORMAT A: /Q /U')
=Sleep(2000)  && wait 2 secs for the format app to start
oShell.AppActivate('\format.com')  &&  select the format app based on the end of the title
oShell.SendKeys('{ENTER}')  &&  Press any key when floppy in drive
=Sleep(500)
oShell.AppActivate('\format.com')  && reactivate
oShell.SendKeys('{Enter}{Enter}')  && Volume Label / Format Another
=Sleep(10000)  && give it 10 seconds to work
oShell.AppActivate('\format.com')
oShell.SendKeys('^C')  &&  Ctrl-C to close session
Format dialogs are not uniform across OS versions, and times depend on the hardware, but it's a start point. AppActivate will use a number of ways to find the right app based on the title text - you can see a description in the VFUG article that George Tasker and I wrote on the Wscript.Shell object. FWIW, the exact code above works on my Win2K box with no trouble as shown, except that it doesn't take a full 10 seconds to finish a QuickFormat of a floppy.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform