如何用BAT判断是否有U盘插在电脑上
2个回答
展开全部
后缀保存为[vbs扩展名],在XP环境下测试通过。本脚本由[知道名字很响亮]原创,转载请注明[出处]
dim Wsh,fso,dc,d
set Wsh = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
do
Set dc = fso.Drives
For Each d in dc
If d.DriveType = 1 Then
If u="" Then
u=d.DriveLetter
MsgBox "你已经插入U盘 "& d.DriveLetter &":"
End if
ElseIf Not fso.DriveExists(u) Then
If u<>"" Then MsgBox "你已经拔出U盘 "& u &":"
u=""
End if
WScript.Sleep 1000
Next
Set dc = nothing
loop
dim Wsh,fso,dc,d
set Wsh = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
do
Set dc = fso.Drives
For Each d in dc
If d.DriveType = 1 Then
If u="" Then
u=d.DriveLetter
MsgBox "你已经插入U盘 "& d.DriveLetter &":"
End if
ElseIf Not fso.DriveExists(u) Then
If u<>"" Then MsgBox "你已经拔出U盘 "& u &":"
u=""
End if
WScript.Sleep 1000
Next
Set dc = nothing
loop
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询