Thursday, July 30, 2009

How to do this in Visual Basic?

I need some help with my visual basic program I would like to to reboot the computer when the user clicks a button but cant get it to work, this is what ive got so far (that dosent work):





Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


Shell("RUNDLL32.EXE shell32,SHExitWindowsEx 2", AppWinStyle.NormalFocus)


End Sub





RUNDLL32.EXE shell32,SHExitWindowsEx 2 is meant to reboot the computer (someone told me) but it just dosent work so does anyone know how I can do it?

How to do this in Visual Basic?
You need to make a Windows API call..."API" stands for "application programming interface", and is a collection of system functions not native to the visual basic environment. There are some good books on these kinds of functions. CHeck a local bookstore. Warning: incorrectly coding an API call can freeze the computer so you have to reboot.
Reply:Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long


Private Const EWX_FORCE = 4


Private Const EWX_LOGOFF = 0


Private Const EWX_REBOOT = 2


Private Const EWX_SHUTDOWN = 1





Private Sub cmdShutDown()


ExitWindowsEx EWX_SHUTDOWN, 0


End Sub


No comments:

Post a Comment