# Run Code at Specific Time and Day VB.NET



## deadscenekid

I am writing a program that will restart my computer at a certain time:

such as: restart my computer at 5:00 A.M. every morning.

Is there any way to check the time and have a Timer object check to see if it is that time and when it is that time restart my computer, also is there a way to make this program run in the task bar only?

Thanks.


----------



## Squashman

Why wouldn't you just use Task Scheduler. Don't even need to use VB to do this.


----------



## Squashman

I have also used this program in the past.
http://users.telenet.be/jbosman/applications.html


----------



## deadscenekid

It was just an idea I had, just a program to write out of boredom.

I thought I would learn how to do it.


----------



## Squashman

I guess if you really want to do it in VB then do it. I don't know VB so I can't help you with that. I try to do things as simple as possible. Use Task Scheduler to run the shutdown command at a specific time or I just use the PowerOff app. If it has already been done I don't try to reinvent the wheel.


----------



## pvc_

> I don't try to reinvent the wheel.


I've actually heard this a few times from different employers (software companies) and no offense to you, it pisses me off. lol... Sometimes they spent hours looking for alternative ways of doing something and gather a bunch of different tools and applications that are written in different languages for different environments, and they spend hours trying to get those apps to work together.... when all they have to do is, ask one of their employees to code a little application that would accomplish all those tasks.

Now going back to the topic. Doing this should be very simple. All you need is a timer that runs every 30 seconds or so, and a few lines of code.

In your timer event you'll have something like this:

'first you need to get the time and date that you want your computer to restart from lets say a textbox:



Code:


dim theTime as datetime

theTime = CDate(txtTime.Text)

if theTime.hour = now.hour and theTime.minute = now.minute then
'shut down code
System.Diagnostics.Process.Start("Shutdown.exe", "-s -t 0")
end if


----------



## deadscenekid

Thanks for your replies guys. I have been coding VB since I was about 12 and I am about to turn 17 right now, so I really am just interested in learning as much as possible about VB.


----------



## Squashman

pvc_ said:


> I've actually heard this a few times from different employers (software companies) and no offense to you, it pisses me off. lol... Sometimes they spent hours looking for alternative ways of doing something and gather a bunch of different tools and applications that are written in different languages for different environments, and they spend hours trying to get those apps to work together.... when all they have to do is, ask one of their employees to code a little application that would accomplish all those tasks.


I agree with you on that in most instances. But for something as simple as this it is really overkill. Whether you are doing this particular function in Batch, VB or using Task Scheduler, you are still calling the same internal Windows program "shutdown"!

And the PowerOff app I posted it perfect for what he wants to do. But I can understand trying to learn to do it himself. But if he wants to learn how to code this then learn how to at least start coding in VB. You know everything starts with "Hello World". Lots of great places on the web to start learning VB. I started with Hello World in Basic, Fortran and Pascal all on an Apple IIe back in the 80's.


----------



## pvc_

Squashman said:


> I agree with you on that in most instances. But for something as simple as this it is really overkill. Whether you are doing this particular function in Batch, VB or using Task Scheduler, you are still calling the same internal Windows program "shutdown"!
> 
> And the PowerOff app I posted it perfect for what he wants to do. But I can understand trying to learn to do it himself. But if he wants to learn how to code this then learn how to at least start coding in VB. You know everything starts with "Hello World". Lots of great places on the web to start learning VB. I started with Hello World in Basic, Fortran and Pascal all on an Apple IIe back in the 80's.


I totally understand your position and like I said my frustration is directed towards managers at software companies who try to save time and money by downloading little applications from different vendors. For instance, at my last job we were using 4 or 5 web applications to keep records of our employees and clients along with both google and msn clients to keep in touch when we could merge all of them in 1 or 2 larger apps and avoid some of the usual confusions...

Anyway, we all approach different problems from different angles for different purposes. deadscenekid likes to learn, you want to get the job done, and I wanna make sure I can implement stuff like this into largers applications...


----------

