System Shutdown from a VB API

Arpagobo

New member
Joined
Jul 8, 2005
Messages
3
Programming Experience
5-10
hi,

I am writing a program in VB .Net (Fred) where I need to be able to shut down the system (Windows 2000 professional or antother NT based Windows) or log off or restart it at the click of a button under my main menu in the API.

Any idea on what sort of code to use for it?

Thank you,
 
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=6d5ba0f2-77c8-43ce-a0ec-4a9a89d47fad take a look at this example ... i think it's much better solution than couple other very simple like Process.Start("Shutdown.exe") or this WIN API one:
VB.NET:
Private Declare Function ExitWindowsEx Lib "User32" Alias "ExitWindowsEx" (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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
 
Call ExitWindowsEx(EWX_LOGOFF, 0) 
 
End Sub

Cheers ;)
 
Hey Body,

I just tried it out, and the Log off worked. I can't wait to test the rest. That helped a lot, and I would like to thank you for the reply man.

Again Thanx a lot!
 
Hi man,

I just tried Shutdown and Reboot, and it did not work. It only works for Log off. I will try other examples from the links. I think the main reason for it is that this sample code is ment for VB 6.0 and not .NET

Cheers,
 
Well, all Win API functions are vb6 ... except those converted in vb.net code. But, it really doesn't matter if it works out ... right?

Ok, this is the link
http://www.mentalis.org/apilist/GetCurrentProcess.shtml (take a look under System Shutdown).

This should resolve your issue. Also this web site is only about API so, you can find any other API solutions ... Note that .NET functions have sign near the title but it doesn't mean that you cannot convert VBx one to .net. Peace of cake, if i may !

Here is how it works for vb.net shutdown function. Basically, it uses the System.Management namespace and creates a management object, sets the appropriate rights before performing the shutdown or restart.

Cheers ;)http://www.mentalis.org/apilist/GetCurrentProcess.shtml
 
Back
Top