vbs脚本应用之午饭抢沙发必备

    在以前公司提供午餐的时候,公司一般会在首页发布用于预定午餐的表单网页,我们需要回复这个表单以确定用餐人数。然后我们吃饭的时候,要在一份名单上签名,上面有每个人的名字。于是谁抢到午餐的沙发,绝对是一件很光荣的事情,如果你成功蝉联好几次,那更是爽的不得了。。。呵呵,是的这就是最简单的快乐,其中滋味只有体会了才知道。于是每个人都绞尽脑汁的想第一时间抢到沙发,拿到这最简单的荣誉光环。有人直接跟管理部打通关节,让他们每次更新网页的时候,人工通知一下。而我属于坐的比较远的,跟管理部混的不熟,所以我决定写个程序抢沙发,想了一下,决定写一个VBS脚本,简单又实用。

    订餐网页比较简单,网址是固定的,只要你在第一时间点击了上面的提交按钮,你就是沙发了。因为管理部在更新网页之前,进入订餐地址会出现错误,而正在更新的时候显示的是不可访问,更新完之后是可以访问。利用这个机制,我做一个个监测脚本,一个订餐简本。监测脚本就是每间隔一段时间不断用ie探测该网页,如果是未更新状态,则ie.title是“错误”,如果不是这个标题。就可以启动订餐脚本开始不断预订的动作了。下面是监测简本

'===================================================================================
'create by dnfchan
'this script is used to watch web page
'===================================================================================
dim WshShell,oc,c
set WshShell = CreateObject("Wscript.shell")
oc=ucase(wshshell.regread("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"))
if oc<>"xxxxxxx" then
msgbox "對不起,您不是xxx先生,無權使用,謝謝!",,"Welcome"
'msgbox "Sorry, you are not MR Deng,So you have no rights to use it, thank you!",,"Welcome"
wscript.quit
end if
msgbox "歡迎您使用,xxx先生!",,"Welcome"
dim ie
set ie = createobject("internetexplorer.application")
ie.visible =0
ie.menubar=0
ie.addressbar=0
ie.toolbar=0
ie.statusbar=0
do
ie.navigate("http://hr-xxxx.xxx.xxxxx/Lists/Survey7/NewForm.aspx")
Do While (ie.Busy or ie.ReadyState<>4) 
    wscript.sleep 100
Loop    
a=ie.Document.Title 
if a<> "錯誤" then 
createobject("wscript.shell").run("D:\book_dinner.vbs")
ie.quit
exit do
end if
loop


开始时身份监测,读取注册表的计算机名,如果不是你自己的电脑名就终止。

因为ie监测比较耗资源,所以把它设置为不可以见,其他参数皆是0,以节省资源消耗。订餐地址不便公开,所以就用xxx代替了。

开始监测,当标题不是错误时候,说明管理部有动作了,那么这个时候启动另一个脚本。它的作用是一直刷新网页,并尝试点击提交按钮,知道成功为止。

代码如下

 

'===================================================================================
'create by dnfchan
'this script is used to order dinner 
'===================================================================================
on error resume next

Dim ws,ie,elemlist
set ws = wscript.CreateObject("wscript.shell")
set ie =wscript.createobject("internetexplorer.application")
ie.visible=true
ie.navigate "http://hr-xxx.xxx.xxxxx/Lists/Survey7/NewForm.aspx"'open ie to access dinner order page
Do While ie.ReadyState<>4 
WScript.Sleep 200
Loop

i=0
'set elemlist = ie.document.getElementsByTagName("input")
'For Each  elem  In elemlist
'If elem.type="checkbox" Then
'elem.checked = true
'i=i+1
'end if
'next

do 
ie.document.all("ctl00$m$g_75aeb5b6_93ae_4c36_af0b_102a6332b308$ctl00$toolBarTbltop$RightRptControls$ctl01$ctl00$diidIOSaveItem").click 'submit the page,success to order dinner
Do While ie.ReadyState<>4 
wscript.sleep 200
Loop

ie.document.location.reload(true)
Do While ie.ReadyState<>4 
Loop
a=ie.Document.Title 
if a="錯誤" then exit do

loop
'msgbox "You are success to book "&i&" dinner",,"Book Success"


订餐脚本不断刷新,点击提交按钮。当再次进入订餐地址出现“错误”title的时候,说明你已经成功了。

整个订餐过程,只要开启了监测脚本就可以了,后面的工作它会全自动进行。最后还是说下,脚本语言学起来真的很简单,这是我学了一天就写出来的

脚本

你可能感兴趣的:(vbs脚本应用之午饭抢沙发必备)