Advance Computer Shutdown using Visual Basic.Net

In this tutorial we’re going to create a simple application that enable a user to shutdown, restart and log off the computer using visual basic. To do this open visual basic and create a new project and name it as “Shutdown”. Designing the user interface: The user interface in this project looks like as shown below. To do this, we need to add three buttons and change their Text property into “Shutdown”,”Restart” and “Log Off”. Add a Label, and change the name into “lblmsg” and the Text property into “Computer will Shutdown in:”. Then add a textbox, and change the font size into “36”,Style into “Bold” and Text into “10” and the backcolor into "Black", then the forecolor to “lime”. And finally add three Timer. This time, we need to add functionality to our application. To do this, double click the timer1 and add the following code: It checks if the value of textbox1 is equal to zero then it will stop the timer and perform the shutting down of computer else, if the value of textbox1 is not equal to zero then it will decrement the value.
  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2.  
  3. If TextBox1.Text = 0 Then
  4.  
  5. Timer1.Stop()
  6. Shell("Shutdown -s")
  7. Else
  8. TextBox1.Text -= 1
  9.  
  10. End If
  11. End Sub
Next for timer2, add the following code: Here in timer2 it simply does the restarting of a computer.
  1. Next for timer2, add the following code:
  2. Here in timer2 it simply does the restarting of a computer.
Next for timer3, add the following code:
  1. Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
  2. If TextBox1.Text = 0 Then
  3.  
  4. Timer3.Stop()
  5. Shell("Shutdown -l")
  6. Else
  7. TextBox1.Text -= 1
  8.  
  9. End If
  10. End Sub
Then for “Shutdown” button, add the following code: It sets the text “lblmsg” to “Computer will Shutdown in:”, then it start the timer1.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. lblmsg.Text = "Computer will Shutdown in:"
  3. Timer1.Start()
  4. End Sub
Then for “Restart” button, add the following code: It sets the text “lblmsg” to “Computer will Restart in:"then it start the timer2.
  1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2. lblmsg.Text = "Computer will Restart in:"
  3. Timer2.Start()
  4. End Sub
Then for “Log off” button, add the following code: It sets the text “lblmsg” to “Computer will Log off in:"then it start the timer3.
  1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  2. lblmsg.Text = "Computer will Log off in:"
  3. Timer3.Start()
  4.  
  5. End Sub
After adding a code, you can start testing the program by pressing “F5”.

Comments

Submitted byndueso (not verified)on Sun, 09/22/2013 - 04:40

good work bro

Add new comment