Aug 5th, 2006, 09:36 PM
#1
Thread Starter
New Member
How to Shutdown PC on Some given Time
Hi,
i want to code this program where i want my PC to shutdown or restart on a given time, is it possible, for e.g i want my PC to restart / shutdown after 5 hours how can i do it.
thanks in advance
Regards
Viking
Aug 5th, 2006, 09:55 PM
#2
Re: How to Shutdown PC on Some given Time
Create a Timer and set its Interval to the number of milliseconds until the desired shutdown time. In the Tick event handler execute the required code to shutdown the machine. There are various ways to do that, e.g, shutdown.exe and the ExitWindowsEx API function, and they have been posted about many times before so a forum search will give you what you need there.
Aug 5th, 2006, 11:10 PM
#3
Lively Member
Re: How to Shutdown PC on Some given Time
I made a shutdown program a while ago here's some of my code to maybe help you out a bit
VB Code:
Timer1.Start()
lblCurrentTime.Text = System.DateTime.Now
If Me.lblCurrentTime.Text.ToString().Equals(Me.dtpTime.Value.ToString()) Then
Private Sub ShutdownAt()
If Me.cbForce.Checked Then
Dim processes() As Process = Process.GetProcesses()
For Each processParent As Process In processes
Dim processNames() As Process = Process.GetProcessesByName(processParent.ProcessName)
For Each processChild As Process In processNames
Try
If Not processChild.MainWindowTitle.Equals(Me.Text) Then
processChild.CloseMainWindow()
processChild.Kill()
processChild.WaitForExit()
End If
Catch exception As Exception
End Try
Next
Next
End If
System.Windows.Forms.Application.Exit()
Select Case cbSelect.SelectedIndex
Case 0
Me.Close()
WindowsController.ExitWindows(RestartOptions.LogOff, True)
Case 1
Me.Close()
WindowsController.ExitWindows(RestartOptions.PowerOff, True)
Case 2
Me.Close()
WindowsController.ExitWindows(RestartOptions.Reboot, True)
Case 3
Me.Close()
WindowsController.ExitWindows(RestartOptions.ShutDown, True)
Case 4
Me.Close()
WindowsController.ExitWindows(RestartOptions.Suspend, True)
Case 5
Me.Close()
WindowsController.ExitWindows(RestartOptions.Hibernate, True)
End Select
'End If
End Sub
Aug 5th, 2006, 11:15 PM
#4
Lively Member
Re: How to Shutdown PC on Some given Time
also here's the wondows controler class you need
Attached Files
Aug 7th, 2006, 01:57 PM
#5
Hyperactive Member
Re: How to Shutdown PC on Some given Time
Where is the heart here. Let a novice crash his computer like that.
Good shut down procudure. NOT!!!! Kill all your processes is bad bad bad!!
VB Code:
If Not processChild.MainWindowTitle.Equals(Me.Text) Then
processChild.CloseMainWindow()
processChild.Kill()
processChild.WaitForExit()
End If
Visual Studio .NET 2005/.NET Framework 2.0
Aug 7th, 2006, 09:47 PM
#6
Fanatic Member
Re: How to Shutdown PC on Some given Time
isn't that what shutting down your pc does? terminate all active processes?
certaintly it's alot cleaner to close them yourself before calling windows to shutdown.
just food for thought though.
Last edited by TokersBall_CDXX; Aug 8th, 2006 at 10:59 AM .
Aug 8th, 2006, 10:41 AM
#7
Lively Member
Re: How to Shutdown PC on Some given Time
Originally Posted by
PENNYSTOCK
Where is the heart here. Let a novice crash his computer like that.
Good shut down procudure. NOT!!!! Kill all your processes is bad bad bad!!
VB Code:
If Not processChild.MainWindowTitle.Equals(Me.Text) Then
processChild.CloseMainWindow()
processChild.Kill()
processChild.WaitForExit()
End If
I put if cbForce is checked if you check it then you choose the option for force shutdown to close out all open program's if not leave it unchecked to just shutdown the basic way it's just a option tho
Aug 8th, 2006, 11:30 AM
#8
Hyperactive Member
Re: How to Shutdown PC on Some given Time
I haven't tried in extesivly, but the second parameter of this tells the shutdown to force it anyway. However, it give the process at least a chance.
VB Code:
WindowsController.ExitWindows(RestartOptions.ShutDown, True)
When I ran you your code, it crashed my system and I recieved the blue screen of death!
.
Visual Studio .NET 2005/.NET Framework 2.0
Aug 8th, 2006, 12:05 PM
#9
Lively Member
Re: How to Shutdown PC on Some given Time
well the program that I made I never got the blue screen of death and the ppl i've had test it haven't either so i'm not sure what the problem maybe
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width