Results 1 to 4 of 4

Thread: VB.NET Shutdown fails to execute in WindowsXP

  1. #1

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    VB.NET Shutdown fails to execute in WindowsXP

    Hello, I have reviewd many of the threads here on how to shutdown a system and created this code using the VB.NET cookbooks solution.

    VB Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.  
    4.     Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    5.  
    6.  
    7.     Private Enum windowsexitflags
    8.         logoff = 0
    9.         Shutdown = 1
    10.     End Enum
    11.     Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click
    12.         MessageBox.Show("Test before")'to see if im going through the button press
    13.         ExitWindowsEx(windowsexitflags.Shutdown, 1&)
    14.         MessageBox.Show(" Test after")
    15.     End Sub
    16.     Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click
    17.         ExitWindowsEx(windowsexitflags.logoff, 0&)
    18.     End Sub
    19.     Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click
    20.         Me.Close()
    21.     End Sub
    22. End Class

    MY Problem is LOGOFF works, SHUTDOWN does not... I do not understand why. Console app is being run on a windows XP SP2 box under administrative privilges. Any sugestions would be appreciated.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: VB.NET Shutdown fails to execute in WindowsXP

    it has to do with rights for the code to be allowed to shutdown windows..

    here is a VB6 article, but the same idea applies in .NET as well..

    http://blogs.msdn.com/brad_mccabe/ar...02/383542.aspx

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: VB.NET Shutdown fails to execute in WindowsXP

    try this:
    VB Code:
    1. Process.Start("Shutdown -s -t 05")
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: VB.NET Shutdown fails to execute in WindowsXP

    here is an artical from vbnet
    Sufficient Rights to shut down windows
    Last edited by TokersBall_CDXX; Jun 10th, 2006 at 10:49 AM.
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

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