Wolfsnap Posted February 13, 2004 Posted February 13, 2004 (edited) I need to able to shut down Windows 2000 in VB.net. I'm developing an application that will run on an industrial PC interface controlling a piece of machinery in a truck. When a "job" is complete, I need to shut down the interface to avoid corrupting the OS and systems on the PC (as opposed to the operator just cutting the power). I've got this code so far, which allows me to restart and log off, but it won't work for a full shutdown. Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer 'Declarations Public Enum ExitWindowsFlags EWX_LOGOFF = 0 EWX_REBOOT = 2 EWX_SHUTDOWN = 1 EWX_FORCE = 4 End Enum Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ExitWindows(0) End Sub I think that I need to set some sort of permissions or authorizations to do a full shutdown, but I am having no luck finding a working example to achieve this. Any help would me EXTREMELY appreciated! Wolf :confused::confused: Edited February 14, 2004 by Derek Stone Quote
Wolfsnap Posted February 14, 2004 Author Posted February 14, 2004 BTW - I've tried all kinds of "settings" for the "ExitWindows" call. 0 logs a user off, and 4 does the same thing, 2 and 1 do nothing. Quote
Wolfsnap Posted February 14, 2004 Author Posted February 14, 2004 Another question - how do I post nice clean VB code in its own window here? (I apologize for my ignorance) Wolf Quote
samsmithnz Posted February 14, 2004 Posted February 14, 2004 I know nothing about logging off winfows, but use the [ code ] tags to post code here. (don't forget to close it with a [/ code ] tag (not spaces) Quote Thanks Sam http://www.samsmith.co.nz
*Gurus* Derek Stone Posted February 14, 2004 *Gurus* Posted February 14, 2004 The process needs to have the SE_SHUTDOWN_NAME privilege granted to it prior to calling [api]ExitWindowsEx[/api](). Request the privilege using [api]AdjustTokenPrivileges[/api](). Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.