编辑以下脚本,检查系统时间是否在凌晨3:05之间。上午05时15分。如果系统在这些小时和timecheckfail.flag之间,如果系统超出这些时间,则脚本应该显示timechecksuccess.flag。我的脚本没有失败。你能告诉我哪里出错了。感谢
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 :(得分: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作为文件的最后一行也没有意义。