Shutdown In VB.NET

Well, nothing happens :)

here u go :


Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4

Private Sub Form_Load()

ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)

End Sub
 
Change all Long declarations to Integers. Also, when using Win2000, XP or 2003 you cant just shut off the computer, your application needs permission.
 
mutant said:
Change all Long declarations to Integers. Also, when using Win2000, XP or 2003 you cant just shut off the computer, your application needs permission.


Can you provide more info on how to provide permissions for 2k and xp?
 
The context in which the procedure is running under. Plaus should be able to give you a more in depth description that this as I havent done it myself for APIs.

Basically when a program runs it runs in the context of the user who started it. There are these things called sePriviledges that a token (a user) has that allows them to do certain system events such as shutting down. the se priveldge is not enabled under 2000 for security reasons, you have to adjust token priveledges to allow it. There are several APIs that you will have to call and use to do this. I remember doing this a year or so ago and finally gave up because it got to complicated at the time. Its possible, Ive seen it, so if you want it that bad its out there. Search MSDN for seAllowShutdown, sePriviledges (I think), AdjustTokenPriviledges (I think - just put Adjust Token if that doesnt come up with anything), and it will lead you to all sorts of information.

I remember MSDN actually has an example on using the shutdown api in .NET and posts a warning as to why it wont work on 2000.

I know this isnt much to go on, but until Plaus or somebody else more experienced with permissions gets back to you, it will give you something to look at....
 
Back
Top