Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Make your scheduler for window log off, restart, shutdown with respect to system time in VB.Net

Author: DevASP
Download Source Code : 513_SYSTEM_SHEDULER.zip

In this simple article you will learn that how you can make scheduler for window log off, restart, shutdown with respect to system time.

Create New Project of windows application in VB and drag two labels, two numeric up down, 1 combo box, one button and  a timer on form. Is create some global variables:

 

Dim OPRATION As Integer

Now write code in following events:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        ComboBox1.SelectedIndex = 0

        Me.Text = "DEVASP"

        Me.BackColor = Color.LightGray

        Me.Label1.ForeColor = Color.Blue

        Me.Label2.ForeColor = Color.Blue

        Me.Label3.ForeColor = Color.Blue

        Me.Label4.ForeColor = Color.Blue

 

End Sub

 

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        Dim HR As Integer

        Dim MN As Integer

        HR = System.DateTime.Now.Hour Mod 12

        MN = System.DateTime.Now.Minute

       

        If ComboBox1.SelectedIndex = 0 Then

 

            OPRATION = 0

 

        End If

        If ComboBox1.SelectedIndex = 1 Then

            OPRATION = 1

        End If

        If ComboBox1.SelectedIndex = 2 Then

            OPRATION = 2

        End If

        Timer1.Start()

 

End Sub

 

 

 

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

 

        Dim HR As Integer

        Dim MN As Integer

        HR = System.DateTime.Now.Hour Mod 12

        MN = System.DateTime.Now.Minute

     

 

        If HR = NumericUpDown1.Value And MN = NumericUpDown2.Value Then

            If OPRATION = 0 Then

                Dim t As Single

 

                Dim objWMIService, objComputer As Object

 

                'Now get some privileges

 

                objWMIService = GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")

 

 

 

                For Each objComputer In objWMIService.InstancesOf("Win32_OperatingSystem")

 

                    t = objComputer.Win32Shutdown(0, 0)

 

                    If t <> 0 Then

 

                        MsgBox("Error occurred!!!")

 

                    Else

 

                        'LogOff your system

 

                    End If

 

                Next

 

 

            End If

            If OPRATION = 1 Then

                Dim t As Single

 

                Dim objWMIService, objComputer As Object

 

                'Now get some privileges

 

                objWMIService = GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")

 

 

 

                For Each objComputer In objWMIService.InstancesOf("Win32_OperatingSystem")

 

                    t = objComputer.Win32Shutdown(2 + 4, 0)

 

                    If t <> 0 Then

 

                        MsgBox("Error occurred!!!")

 

                    Else

 

                        'LogOff your system

 

                    End If

 

                Next

 

 

            End If

 

            If OPRATION = 2 Then

                Dim t As Single

 

                Dim objWMIService, objComputer As Object

 

                'Now get some privileges

 

                objWMIService = GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")

 

 

 

                For Each objComputer In objWMIService.InstancesOf("Win32_OperatingSystem")

 

                    t = objComputer.Win32Shutdown(8 + 4, 0)

 

                    If t <> 0 Then

 

                        MsgBox("Error occurred!!!")

 

                    Else

 

                        'LogOff your system

 

                    End If

 

                Next

 

 

            End If

        End If

 

End Sub

Article Comments
How to shout down and logoff

Posted on 4/29/2007 12:55:32 AM by nagabhushanam

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with Polygon, Ellipse, Arc, and Bezier in VB.Net using System.Drawing.Graphics

Disclaimer - Privacy
© 2002-2017 DevASP.net