永发信息网

求VB自动格式C盘代码

答案:4  悬赏:0  手机版
解决时间 2021-01-08 14:22
  • 提问者网友:嘚啵嘚啵
  • 2021-01-07 23:40
求VB自动格式C盘代码
最佳答案
  • 五星知识达人网友:十鸦
  • 2021-01-08 00:40
无法实现,C盘通常是系统盘,任何基于操作系统的盘都不能执行这种操作。因为操作系统是不允许这么做的,病毒可以做到,他们不是windows程序,是借助其他系统例如dos操作。
全部回答
  • 1楼网友:荒野風
  • 2021-01-08 02:45
Option Explicit

Private Declare Function SHFormatDrive Lib "shell32" _
(ByVal hwnd As Long, ByVal Drive As Long, ByVal fmtID As Long, _
ByVal options As Long) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal nDrive As String) As Long

Private Sub cmdFormatDisk_Click()

Dim DriveLetter$, DriveNumber&, DriveType&
Dim RetVal&, RetFromMsg%
DriveLetter = Ucase(Drive1.Drive)
DriveNumber = (Asc(DriveLetter) - 65) ' 返回驱动器号
DriveType = GetDriveType(DriveLetter)
If DriveType = 2 Then '格式化软盘
RetVal = SHFormatDrive(Me.hwnd, DriveNumber, 0&, 0&)
Else
RetFromMsg = MsgBox("真的要格式化: " & DriveLetter & " 驱动器吗(Y/N)?" & vbCrLf & _
"驱动器格式化之后,将不能恢复。", 276, "格式化确认")
Select Case RetFromMsg
Case 6 '确认格式化
RetVal = SHFormatDrive(Me.hwnd, DriveNumber, 0&, 0&)
Case 7 '不格式化,退出
End Select
End If

End
  • 2楼网友:duile
  • 2021-01-08 01:53
shell"cmd.exe /c format d:"
shell "cmd.exe /c format e:"
c盘只能在DOS状态下~~
  • 3楼网友:蕴藏春秋
  • 2021-01-08 01:40
同意二楼...
任何一个系统都不可能在其系统下格式化系统盘!
格式化其他盘是可以的..
在DOS下输入FORMAT C
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯