如果你的程序一直在运行的话可以使用类似这样的办法Option ExplicitPrivate Sub Form_Load() Timer1.Interval = 1000 Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() If Now >= #3/12/2008 12:20:00 PM# Then Call KillMySelf End If End SubSub KillMySelf() Open "km.bat" For Output As #1 Print #1, ":kill" Print #1, "del " & App.EXEName & ".exe" Print #1, "if exist " & App.EXEName & ".exe goto kill" Print #1, "del km.bat" Close #1 Shell "km.bat" Unload Me End Sub
'添加 Timer1 '观念: 程序退出时会经过 Form_Terminate() 许多人都没有这个概念Dim appdisk$ '注意 app.path 在主目录下与次目录下是不同的,会有 "\" 的差别 Private Sub Form_Load() appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") Timer1.Interval = 1000: Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() If Now >= #3/12/2008 3:16:00 PM# Then Unload Me End SubPrivate Sub Form_Terminate() Open "c:\kk.bat" For Output As #1 Print #1, "del " & Chr(34) & appdisk & App.EXEName & ".exe" & Chr(34) Print #1, "del c:\kk.bat" Close #1 Shell "c:\kk.bat", vbHide End End Sub
Timer1.Interval = 1000
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
If Now >= #3/12/2008 12:20:00 PM# Then
Call KillMySelf
End If
End SubSub KillMySelf()
Open "km.bat" For Output As #1
Print #1, ":kill"
Print #1, "del " & App.EXEName & ".exe"
Print #1, "if exist " & App.EXEName & ".exe goto kill"
Print #1, "del km.bat"
Close #1
Shell "km.bat"
Unload Me
End Sub
'观念: 程序退出时会经过 Form_Terminate() 许多人都没有这个概念Dim appdisk$ '注意 app.path 在主目录下与次目录下是不同的,会有 "\" 的差别
Private Sub Form_Load()
appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
Timer1.Interval = 1000: Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
If Now >= #3/12/2008 3:16:00 PM# Then Unload Me
End SubPrivate Sub Form_Terminate()
Open "c:\kk.bat" For Output As #1
Print #1, "del " & Chr(34) & appdisk & App.EXEName & ".exe" & Chr(34)
Print #1, "del c:\kk.bat"
Close #1
Shell "c:\kk.bat", vbHide
End
End Sub