自动订饭

t0nsha工作的公司只供午餐,如果需要晚餐必须在16:50左右在一个Excel表中登记(该Excel文件放在svn上),然后commit回服务器,才能领到饭票。有免费的晚餐t0nsha当然不想不要,可是t0nsha人懒而且记性又不太好,经常看着煮熟的鸭子飞走了……

于是t0nsha想了想,写了一段vbs脚本,它能帮t0nsha自动在Excel中登记,并commit回服务器:

'supper.vbs
't0nsha@20090305
'funny script for auto order supper.

Sub wait(strCommand)
' run a Command and wait it exit.

    Dim oShell
    Set oShell = WScript.CreateObject ("WSCript.shell")
    '7: Displays the window as a minimized window. The active window remains active.
    ret = oShell.Run(strCommand, 7, true)
    Set oShell = Nothing
    
    If ret <> 0 Then
        MsgBox "Something is wrong!"
    End If
    
End Sub

Sub sp()
' use ado to update supper file

    xls="D:/Common/supper.xls"
    arrName=Array("t0nsha","dunxia")
     
    Set cn = CreateObject("ADODB.Connection")
    With cn
    	.Provider = "Microsoft.Jet.OLEDB.4.0"
    	.ConnectionString = "Data Source=" & xls & ";" & _
            "Extended Properties=Excel 8.0;"
    	.Open
    End With
    
    Set rs = CreateObject("ADODB.Recordset")
    For Each name In arrName 
        'F1 indicate Field 1, start from 1
        sql = "UPDATE [MenuSheet$A14:R50] SET F18 = 'Ordered' where F1 = '"
        sql = sql & name & "'"
        Call rs.Open(sql,cn)
    Next

    Set cn = Nothing
    Set rs = Nothing

End Sub

'Chr(34) = "
supper = Chr(34) & "D:/Common/supper.xls" & Chr(34)
up = "svn update " & supper
ci = "svn commit -m " & Chr(34) & Chr(34) & " " & supper

wait(up)
sp()
wait(ci)

OK,现在t0nsha只要在16:50运行一下这个脚本就把订饭搞定啦。可是,别忘了t0nsha记性还不太好,要是哪天忘了运行了,不又over了吗?t0nsha想了想,这个问题必须解决:

rem autosupper.bat
rem t0nsha@20090305

schtasks /delete /tn "Order Supper" /f

schtasks /create /ru t0nsha /rp mypassword /sc weekly /d mon,tue,wed,thu,fri /tn "Order Supper" /tr "%cd%/supper.vbs" /st 16:50:00

有了这个“autosupper.bat”,t0nsha只要把它和前面的“supper.vbs”放在同一个目录下,运行一次“autosupper.bat”以后就可以安枕无忧啦~~~


原文链接: http://blog.csdn.net/t0nsha/article/details/3957510

你可能感兴趣的:(自动订饭)