这是今年中秋节写的。早上收到老同事发的短信,觉得有必要回复一下。公司有个网页可以供员工发手机短信,但要想群发,必须申请,领导批准。领导怎么会批准我这样的申请?还好,刚学了写脚本,那就学以致用,自己动手、丰衣足食吧。
这个脚本很简单,主要就是用了SendKeys方法模拟键盘敲字;使用clipboardData.SetData方法将文件内容复制到剪贴板。脚本仅在我公司可用,但思路是通用的,可以将各种单发短信的软件,改造成群发短信。只要不发垃圾短信就好了!
下面是我写的操作过程的最佳实践,发邮件给了本部门除领导外的几位同事:
1、添好两个文件“c:\短信内容.txt”、“c:\手机列表.txt”。手机列表是一行一个号码,如:
13312345678
13323456789
2、其它窗口最小化,仅保留下图一个窗口即可。
3、“短信群发.vbs”放在桌面上就可以了,双击它,一切OK。
4、如要中断脚本,可以去任务管理器中杀掉wscript.exe或cscript.exe。winXP和win2003也可以用命令行:
wmic process where name="wscript.exe" call terminate
wmic process where name="cscript.exe" call terminate
附:“短信群发.vbs”脚本内容:
Content = "c:\短信内容.txt"
PhoneList = "c:\手机列表.txt"
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Content, ForReading)
ReadAllTextFile = objTextFile.ReadAll
If len(ReadAllTextFile) >50 Then
Wscript.echo "短信内容最大长度为50,实际长度为:" & len(ReadAllTextFile)
WScript.Quit
End If
set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", ReadAllTextFile
objIE.Quit
set WshShell = CreateObject("WScript.Shell")
Set objTextFile = objFSO.OpenTextFile(PhoneList, ForReading)
Do While objTextFile.AtEndOfStream <> True
WshShell.AppActivate "https"
WScript.Sleep 1000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys objTextFile.Readline
WScript.Sleep 1000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "^v"
WScript.Sleep 1000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000
Loop