用BAT和VBS搜集AD中的客户PC资料
看完了要回复啊,提高一下我的BLOG人气~
[版权所有,同属两人,谢谢浏览]
最近想写一个脚本,用来处理工作中的事务,具体的需求还没怎么想好,但是就想实现这样一个功能,不用亲自的去客户端机器搜集信息,把脚本放在AD服务器上,客户登陆的时候就可以运行,也可以增加一个AD策略,将所有的信息搜集,发到指定的邮箱里!
下面是我搜集客户信息的一些DOS命令
================================================
systeminfo >c:\star.rtf
ipconfig |find "IP Address">>c:\star.rtf
route print >>c:\star.rtf
netstat -an |find "LISTENING" >>c:\star.rtf
=================================================
%1"== 这个参数是在 运行BAT的时候需要你输入的,有空格~
将下面保存为sendmail.bat 运行 sendmail.bat yourmail@yourmailserver.com
@echo off
REM MAIL Setting
if "%1"=="" goto :show
::这里你可以任意的加DOS命令[可以参考我上面的命令]
::cd \ && c: && cd pro* && cd winrar
::rar a c:\star.rar c:\star.rtf
set Mexecfile="S_MAIL.vbs"
set mailfrom=/fr "yourmail@yourmailserver.com.cn"
set mailto=/to "%1"
set mailsub=/sub "客户PC系统在%date% %time%的状态"
:: Mail mess
set mailmes=/mes "[这个是一个自动发邮件的脚本,检测客户PC的运行状态]"
:: User Name
set user=/muser "yourmailusername"
:: Password
set password=/mpasswd "yourmailpassword"
set add=/add "c:\star.rtf"
REM smtpServer
::推荐用126邮箱,或者smtp为端口为25的。
rem set smtpServer=/s "smtp.gmail.com"
set smtpServer=/s "mail.yourmailserver.com"
set other=/sh /mail /au %add%
%Mexecfile% %smtpServer% %mailto% %mailFrom% %user% %password% %mailsub% %mailmes% %other%
:Show
echo plz type u want mailto mail address
goto :End
:End
================================================
下面是一个热心的朋友给我写的vbs,主要的功能都在这里~
——————————————————————————————
——————————————————————————————
再次感谢台湾的程序员的帮助,谢谢,不好提名~ 心知
存为 S_MAIL.vbs
' *************************************************
' S_mail.vbs 2005'12'27
' S_mail.vbs /s 192.168.1.10 /to test@test.com.tw /cc test@test.com.tw /fr log@MAIL /sub "testaa" /mes aaa /sh /MAIL
' edit 2006/01/04
' edit 2006/01/07
' edit 2006/01/12
' edit 2006/12/07
' *************************************************
Option Explicit
' *********************** DIM *********************
dim mailfrom,mailto,mailcc,mailsub,mailmess,MXserver,mailsmtpport,mailuser,mailpasswd
dim objEmail,msgerr
Dim stry,strm,strd,strtxt
dim fush,fuc
Dim strFlag,intState,i
Dim objFileSystem
dim FSO,objfile,ReadAllTextFile
dim add,addfile,userpd
dim strsmptaut,smptaut,htmlchk
dim strsmtpssl,smtpssl
' ***********************EDIT ***********************
' *********************** PROGRAM ***********************
call argm
CALL funchk
' ***********************SUB PROGRAM ***********************
sub argm
if Wscript.arguments.Count > 1 then
add = 0
userpd = 0
mailsmtpport = 25
for i = 0 to Wscript.arguments.Count -1
select case LCase(Wscript.arguments.Item(i))
case "/s"
MXserver = LCase(Wscript.arguments.Item(i+1))
case "/to"
mailto = LCase(Wscript.arguments.Item(i+1))
case "/cc"
mailcc = LCase(Wscript.arguments.Item(i+1))
case "/fr"
mailfrom = LCase(Wscript.arguments.Item(i+1))
case "/sub"
Mailsub = LCase(Wscript.arguments.Item(i+1))
case "/mes"
mailmess = LCase(Wscript.arguments.Item(i+1))
if mailmess = "file" then
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objfile = FSO.OpenTextFile(Wscript.arguments.Item(i+2),1)
ReadAllTextFile = objfile.ReadAll
objfile.close
end if
case "/add"
add = 1
addfile = LCase(Wscript.arguments.Item(i+1))
case "/html"
htmlchk=1
case "/muser"
userpd = userpd + 1
mailuser = LCase(Wscript.arguments.Item(i+1))
case "/mpasswd"
userpd = userpd + 1
mailpasswd = Wscript.arguments.Item(i+1)
case "/au"
strsmptaut = "Yes"
smptaut = 1
case "/ssl"
strsmtpssl = "Yes"
SmtpSSL = 1
case "/sport"
mailsmtpport =int(Wscript.arguments.Item(i+1))
case "/sh"
fush = 1
case "/mail"
fuc = 1
end select
next
else
call usage
end if
end sub
sub funchk
if mailto = "" or mailfrom = "" or Mailsub = "" or mailmess = "" or MXserver = "" then
if mailfrom = "" then mailfrom = "/fr Mail From"
if mailto = "" then mailto = "/to Mail To"
if Mailsub = "" then Mailsub = "/sub Subject"
if mailmess = "" then mailmess = "/mes Message"
if MXserver = "" then MXserver = "/s Smtp Server"
call showlok
wscript.echo "You can type mal.vbs /? or mal.vbs "
wscript.quit
end if
if fush = 1 then call showlok
if fuc = 1 then call mlt
end sub
sub usage
wscript.echo ""
wscript.echo ""
wscript.echo "Executes a command."
wscript.echo ""
wscript.echo " SYNTAX: "
wscript.echo ""
wscript.echo " [/s ] "
wscript.echo " [/to ] [/cc] [/fr ]"
wscript.echo " [/sub ] [/mes | file FileName ] "
wscript.echo " [/sh ] [/mail ]"
wscript.echo " [/add ]"
wscript.echo " [/au ]"
wscript.echo " [/SSL ]"
wscript.echo " [/html ]"
wscript.quit
end sub
sub showlok
wscript.echo ""
wscript.echo "MAIL FROM : " & mailfrom
wscript.echo "MAIL TO : " & mailto
wscript.echo "MAIL SUB : " & Mailsub
wscript.echo "MAIL MESS : " & mailmess
wscript.echo "SMTP Server : " & MXserver
if smptaut = 1 then wscript.echo "SMTP Authenticate: " & strsmptaut
if smtpssl = 1 then wscript.echo "SMTP SSL: " & strSmtpSSL
if htmlchk=1 then wscript.echo " HtmlBody Send"
wscript.echo
end sub
'*********
sub mlt
Set objEmail = CreateObject("CDO.Message")
if mailmess = "file" then mailmess = ReadAllTextFile
with objEmail
.From = mailfrom
.To = mailto
.cc = mailcc
.Subject = mailsub
if htmlchk=1 then
.htmlbody=mailmess
else
.Textbody = mailmess
end if
'Ж郎
if add = 1 then
.AddAttachment addfile
end if
if userpd = 2 then
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailuser
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpasswd
end if
if smptaut = 1 then
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
end if
if smtpssl = 1 then
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
end if
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MXserver
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = mailsmtpport
.Configuration.Fields.Update
.Send
end with
end sub
'**********
' end
综上所述,你就可以发信了~ 有不明白的可以
sendMail to Me star33375249(at)gmail(dot)com