2013-11-04 29 views
0

編輯以下腳本來檢查系統時間是否在上午3:05之間& 5:15 am。如果系統在這些時間之間,腳本應該顯示timechecksuccess.flag,如果系統在這些時間之外,腳本應該顯示timecheckfail.flag。我的腳本沒有失敗,因爲它應該。你能告訴我我要去哪裏嗎?由於VB腳本來檢查系統是否在特定時間

Option Explicit`enter 
On Error Resume Next 

Dim g_objShell, g_strTSuccess, g_strTFail, g_objFS, g_strDone 

Set g_objShell = CreateObject("WScript.Shell") 
Set g_objFS = CreateObject("Scripting.FileSystemObject") 

g_strTSuccess = "C:\TimeCheckSuccess.Flag" 
g_strTFail = "C:\TimeCheckFail.Flag" 
g_strDone = "C:\Done.Flag" 

If g_objFS.FileExists(g_strTSuccess) Then 
Call g_objFS.DeleteFile(g_strTSuccess, True) 
End If 

If g_objFS.FileExists(g_strTFail) Then 
Call g_objFS.DeleteFile(g_strTFail, True) 
End If 

If g_objFS.FileExists(g_strDone) Then 
Call g_objFS.DeleteFile(g_strDone, True) 
End If 

If DatePart("h" ("n", Now()) < 0305 or DatePart("h" ("n", Now()) > 0515 or     WScript.Arguments.Named.Exists("Now")))Then 

Call g_objFS.CreateTextFile(g_strTSuccess, True) Else 
Call g_objFS.CreateTextFile(g_strTFail, True) 

結束如果

Call g_objFS.CreateTextFile(g_strDone, True) 

Set g_objShell = Nothing 
Set g_objFS = Nothing 

Wscript.Quit 

回答

0
If Time() > TimeValue("3:45am") then msgbox "After 3:45am" 
If Time() < TimeValue("8:00pm") then msgbox "Before 8pm" 

和,而不是這種編碼。

If g_objFS.FileExists(g_strDone) Then 
    Call g_objFS.DeleteFile(g_strDone, True) 
End If 

只需刪除文件。你不測試然後做,然後你測試。你也不會使用通話。如果你關心它是否成功刪除。

on error resume next 
g_objFS.DeleteFile("C:\Done.Flag", True) 
If err.number = 53 Then 
    msgbox "File didn't exist" 
elseif err.number <> 0 then 
    msgbox "unknown error" 
End If 
on error goto 0 

此外,將wscript.quit作爲文件的最後一行是毫無意義的。

相關問題