用VB6.0编写磁盘格式化程序
4722 点击·0 回帖
![]() | ![]() | |
![]() | 软盘是数据的常用载体,我们的软件可能会提供用户将数据备份到软盘上的功能。为避免软盘上有带有病毒的文件,最安全的办法就是提醒用户将软盘格式化。 Visual Basic可以通过调用API函数格式化一个磁盘,无论是软盘还是硬盘。 打开一个新的项目(project1) ,如果你没有更改过缺省模式,那么Visual Basic会自动添加一个form1文件,在form1上添加一个命令控件,将下面的代码拷入。 Option Explicit Private Declare Function SHFormatDrive Lib"shell32"_ ( ByVal Hend AS Long,_ ByVal Drive AS Long,_ ByVal FormatID AS Long,_ ByVal Options AS Long) as Long Private Sub FormatDisk(intDrive as integer,blnQuickFormat as Boolean) dim lngReturn As Long; if (blnQuickFormat) then lngReturn= SHFormatDrive(0,intDrive,0;,1;) else lngReturn= SHFormatDrive(0,intDrive,0;,0;) end if end Sub Private Sub Command1_Click() call FormatDisk(0,True) End Sub 运行此程序。 这里有必要提醒读者注意的是,FormatDisk函数的第一个变量很重要,他的值是0,1,2时代表格式化的分别是:A、B、C盘。 注意:读者使用此程序作练习的时候千万不要用硬盘作实验,笔者不为可能发生的错误和损失负责。 | |
![]() | ![]() |