Results 1 to 3 of 3

Thread: How to shutdown computer in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    8

    How to shutdown computer in vb.net

    Try this code :


    'Add System.Management Reference in your vb.net program

    Imports System
    Imports System.Management
    Public Class clsWMI
    Private obj As Object
    Public Enum ShutDownOptions
    LogOff = 0
    SHUTDOWN = 1
    REBOOT = 2
    FORCE = 4
    POWEROFF = 8
    End Enum
    Public WriteOnly Property ShutDown() As Integer
    'Value should be ShutDownOptions
    Set(ByVal Value As Integer)
    For Each obj In GetObject("winmgmts:{(shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
    obj.Win32Shutdown(Value)
    Next
    End Set
    End Property
    end Class

    'Create a new form and add following code in calling procedure which will shutdown your comuter

    Dim obj As New clsWMI
    obj.ShutDown = obj.ShutDownOptions.SHUTDOWN + obj.ShutDownOptions.FORCE

    It works Gr8 !!!!
    Hiren

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Despite the fact that it probably does untold damage to several key systems, yeah I expect it does exactly what it says on the tin.

    You'll excuse me if I don't run it

    I advise caution to anyone thinking of running that code.
    I don't live here any more.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    8
    Could you please explain what kind untold damage to several key systems ? Since this is managed code and we are using WMI. But If you know something I would like to know.

    thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width