CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Shutdown winnt

  1. #1
    Join Date
    Oct 2001
    Posts
    93

    Shutdown winnt

    How do I shutdown or log off a computer in win2000 (nt version). Can you give me a sample project. Thanks


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Shutdown winnt


    'Declarations
    Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (byval uFlags as Long, byval dwReserved as Long) as Long
    public Enum ExitWindowsFlags
    EWX_LOGOFF = 0
    EWX_REBOOT = 2
    EWX_SHUTDOWN = 1
    EWX_FORCE = 4
    End Enum




    and to use it:

    public Sub ExitWindows(byval Mode as ExitWindowsFlags)

    Call ExitWindowsEx(Mode,0)

    End Sub




    HTH,
    D.

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Shutdown winnt

    I don't think it works in Windows NT (or at least in 2000) does it? ...

    ----------
    The @host is everywhere!
    ----------

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Shutdown winnt

    'Works only on NT

    Private Declare Function InitiateSystemShutdown Lib "advapi32.dll" Alias "InitiateSystemShutdownA" (ByVal lpMachineName As String, ByVal lpMessage As String, ByVal dwTimeout As Integer, ByVal bForceAppsClosed As Long, ByVal bRebootAfterShutdown As Long) As Long
    Private Declare Function AbortSystemShutdown Lib "advapi32.dll" Alias "AbortSystemShutdownA" (ByVal lpMachineName As String) As Long


    Public Function ShutDownComputer(CompName As String, MessageToUser As String, SecondsUntilShutdown As Long, ForceAppsClosed As Integer, RebootAfter As Integer)
    ShutDownComputer = InitiateSystemShutdown(CompName, MessageToUser, SecondsUntilShutdown, ForceAppsClosed, RebootAfter)
    End Function


    Public Function AbortShutdown(CompName As String)
    AbortShutdown = AbortSystemShutdown(CompName)
    End Function

    ' + Shutdown can only be aborted while the countdown is going.
    ' + Both Functions return "0" when failed, or "1" when Successful.

    Private Sub cmdAbort_Click()
    Call AbortShutdown(txtCompName)
    MsgBox "Shut down is aborted"
    End Sub

    Private Sub cmdExit_Click()
    Unload Me
    End Sub

    Private Sub cmdShut_Click()
    Dim Ret
    Dim msg As String

    msg = "Your Computer will be shut down in " & txtDelay & " sec."
    Ret = ShutDownComputer(txtCompName, msg, Val(txtDelay), 2, 5)
    Select Case Ret
    Case 0
    MsgBox "Shut down failed."
    Case 1
    MsgBox "Computer " & txtCompName & " is successfully shut down."
    End Select
    End Sub


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured