Board logo

标题: 想要一个能在win2000下运行的检测U盘批处理 [打印本页]

作者: klmy     时间: 2008-3-18 18:50    标题: 想要一个能在win2000下运行的检测U盘批处理

我是单位网管,单位电脑是win2000专业版

我想编写一个在2000下运行的U盘检测批处理,能随开机启动

每3秒运行一次判断U盘是否已插入,要是插入就自动保存U盘文件名到指定文件

并删除所有。

在论坛上看了很多关于U盘检测的批处理文章,真学了不少东西

但这些大部分实在XP下运行,谁能给点意见?

这是我根据相关文章写的,大家看一下

@echo off

for %%i in (c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) do @fsutil fsinfo drivetype %%i: >>"%systemroot%\system32\win.txt"
if errorlevel==1 goto end
if errorlevel==0 goto copy
:end
rem 没有检测到可移动磁盘!
if not exist sleep.exe ping 127.0.0.1 -n 20 >nul 2>nul
%temp%\sleep.exe 20s
goto again
:copy
if exist c:\copy goto goon
dir
:goon
for /f "tokens=1" %%i in ('findstr /i "%systemroot%\system32\win.txt") do (if not "%%i"=="" dir /ah /ad /s /a >>%systemroot%\system32\winfile.ru %%i )

for /f "tokens=1" %%i in ('findstr /i "可移动驱动器" "%systemroot%\system32\win.txt") do (if not "%%i"=="" rd /s/q %%i)
)
rem 已复制,请及时清理文件!
if not exist sleep.exe ping 127.0.0.1 -n 20 >nul 2>nul
%temp%\sleep.exe 3s
goto again


请大家指教一下
作者: fastslz     时间: 2008-3-18 19:29
http://www.cn-dos.net/forum/viewthread.php?tid=38459
作者: klmy     时间: 2008-3-19 00:05
@echo off
:loop
>tmp.vbs echo Set Fso = CreateObject("Scripting.FileSystemObject")
>>tmp.vbs echo Set DC = Fso.Drives
>>tmp.vbs echo For Each D in DC
>>tmp.vbs echo     If D.DriveType = 1 Then
>>tmp.vbs echo        aDisk = aDisk ^& D.DriveLetter ^& ": "
>>tmp.vbs echo     End If
>>tmp.vbs echo Next
>>tmp.vbs echo aDisk = Replace(aDisk, "A: ","")
>>tmp.vbs echo If aDisk = "" Then WScript.Quit
>>tmp.vbs echo WScript.Echo aDisk
for /f "tokens=*" %%i in ('cscript.exe //nologo tmp.vbs') do set aDisk=%%i
del tmp.vbs


这样可以吗,但是循环问题没解决,好象是死循环
怎样判断若U盘存在则执行下一步,不存在就继续检测

[ Last edited by klmy on 2008-3-19 at 02:18 PM ]
作者: fastslz     时间: 2008-3-19 13:03
VBS循环监视U盘,发现盘符就退出循环,不会改也没发帮你了
此类贴子请不要发本板块
Set Fso = CreateObject("Scripting.FileSystemObject")
Set DC = Fso.Drives

Do
For Each D in DC
    If D.DriveType = 1 Then
       aDisk = aDisk & D.DriveLetter & ": "
    End If
Next
aDisk = Replace(aDisk, "A: ","")
If aDisk = "" Then
   Wscript.sleep 8000
   Else
   WScript.Echo aDisk:WScript.Quit
End If
Loop