Dim wShell,fso,objFileName
'输入搜索目标
objFileName=InputBox("请输入要查找的文件名;"&vbCr&vbCr&"或者文件夹名。按确定开始查找。","查找文件或者文件夹路径","chrome.exe")
'判断是否输入目标 没有退出
If objFileName="" Then WScript.Quit
'创建文件对象
Set fso=CreateObject("Scripting.FileSystemObject")
Set wShell=CreateObject("Wscript.Shell")
For Each oDrive In fso.Drives
If oDrive.DriveType<>4 Then
strDrives=strDrives&oDrive.Path&"\ "
End If
Next
'搜索文件
cmd="cmd.exe /c for %1 in ("&strDrives&") do dir %1"&objFileName&" /b /s>>搜索结果.txt"
wShell.Run cmd,False,True
'创建搜索结果文件
Set txt=fso.OpenTextFile("搜索结果.txt",1)
If Not txt.AtEndOfStream Then
X=txt.ReadAll
End If
txt.Close
iReturn=wShell.Run("搜索结果.txt")
WScript.Sleep 1000
fso.DeleteFile "搜索结果.txt",False
X=Replace(X,"Program Files","Progra~1")
X=Replace(X,Chr(13),"")
X=Split(X,Chr(10))(0)
wShell.Run "cmd /c echo " & X & "| clip.exe",0,False
If MsgBox("是否打开?",vbOKCancel)=1 Then
If fso.FolderExists(X) Then
wShell.Run "explorer " & Chr(34) & X & Chr(34)
Else
wShell.Run X
End if
End If