Program to Shutdown - Restart - or Log Off Computer - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This tutorial will show you how to create a Shutdown utility in visual basic .net.

The program created will be used to perform operations such as shutting down the computer, restart it or log off the user

I’m using Visual Studio 2008 but it will work on express even if not studio.

Change the form name to whatever you want.

visual basic .net shutdown computer

Set the maximize box and minimize box property to “false”. Change formborderstyle to FixedSingle.

visual basic .net restart computer

vb.net shutdown utility

Add 3 Groupboxes and 3 buttons to the form.

log off computer vb.net

Rename the controls:

GroupBox1 = Shutdown

Groupbox2 = Restart

Groupbox3 = Log Off

Button1 = Click here to Shut Down

Button2= Click here to restart

Button3=Click here to Log Off.

rename groupbox for shutdown utility in visual basic .net

It should look like on the left.

Now add the code for “Click here to shut down” button click event:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Shell("shutdown -s")
End Sub

Now add the code for “Click here to Restart” button click event.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Shell("shutdown -r")
End Sub

Now add the code for “Click here to logoff” click event

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Shell("shutdown -l")
End Sub

NOTE: If you debug and click on shutdown, it will shutdown, causing you to lose your work if unsaved.


Share This

Home | About | Contact | Privacy Policy

Copyright © visual-basic-tutorials.com 2017 - All Rights Reserved.