Rebooting from a vb.net app

N

NetworkElf

Hi all,

I'm trying to create an app that will reboot the machine upon which it is
running. I've set up ExitWindowsEx as shown below, but I seem to have done
something wrong, as nothing happens when the button associated with the
reboot command is pushed.

From what I can see of the code I have googled, the syntax looks right.
Would someone please give me a nudge in the right direction?

Thank you.



Public Class Form1
Inherits System.Windows.Forms.Form
Const EWX_REBOOT = 2
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As
Long, _
ByVal dwReserved As Long) As Long


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim lr As Long

lr& = ExitWindowsEx(EWX_REBOOT, 0)
MsgBox(lr)

End Sub

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

Herfried K. Wagner [MVP]

NetworkElf said:
I'm trying to create an app that will reboot the machine upon which it is
running. I've set up ExitWindowsEx as shown below, but I seem to have done
something wrong, as nothing happens when the button associated with the
reboot command is pushed.

Your declares are wrong. Solution:

<URL:http://www.mentalis.org/soft/class.qpx?id=7>
 
C

Crouchie1998

Mine is a fully working VB.NET example, but please give me a mention in your
application if you use my code because I was the first to post the code on
the Internet for VB.NET.

Crouchie1998
BA (HONS) MCP MCSE
 
N

NetworkElf

Crouchie1998 said:
Mine is a fully working VB.NET example, but please give me a mention in your
application if you use my code because I was the first to post the code on
the Internet for VB.NET.

Crouchie1998
BA (HONS) MCP MCSE

Actually, it seems that my little app will not go into production. The user
said that a server needed to be rebooted automatically once a day, so I
decided that this would be a good learning project for vb.net and started
working on it.

However, it seems that what really happening is that a set of services are
being stopped/started each morning and when the application to which they
are related has communications issues. I'll take that up as a project when I
return from leave.

Thanks again.

ne.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top