Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timed shutdown

Status
Not open for further replies.

jozino01

Technical User
Apr 25, 2003
257
CA
hi, i want to create a program which would prevent computer running in defined time period (it would shutdown)

i wrote some code but it's not working :-(
when started it has status non-responding.

Option Explicit
Dim notime As String
Dim RETVAL2 As Variant
Declare Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)
Sub main()
On Error GoTo ex1
notime = Format(Time, "hhmmss")
nav1:
If notime > "000001" And notime < "060000" Then
RETVAL2 = Shell("C:\windows\system32\shutdown.exe -s -f -t 00")
End If
Sleep 60000
GoTo nav1
ex1:
MsgBox Err.Description, 16, "Error message. "
Resume Next
End Sub

any suggestion please?
 
Sleep() is a "hang" and if you hang too long without running the message loop, Windows assumes your program... is hung!

You can insert a DoEvents() call after the Sleep() or better yet drive your time testing with a Timer control event, discarding that GoTo loop.
 
thanks
i am not using any form, just module so i can't use timer or can i?
can you please give me some sample code using DoEvents() call after the Sleep()?
 
I would have thought that:

Option Explicit
Dim RETVAL2 As Variant

Sub main()
If Time < "060000" Then
RETVAL2 = Shell("C:\windows\system32\shutdown.exe -s -f -t 00")
End If
End Sub

Would be sufficient or am I missing something.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
to error7
well, i want to allow computer run any time, but shut it down after midnight and shut it down right away if started between midnight and 6am.
so i need to check time periodically and shutdown if time is between midnight and and 6am.
 
Sorry, I thought you wanted to prevent it from being fired up before 06:00.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top