Solved

VB.NET force reboot

Posted on 2004-08-24
13
689 Views
Last Modified: 2012-08-13
I need to be able to force reboots on Win 2k and XP pro machines using VB.NET.  Does anyone know how this is done?
0
Comment
Question by:forrest321
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 19

Assisted Solution

by:Desp
Desp earned 25 total points
ID: 11882347
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 50 total points
ID: 11883706
Just need this:

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

ExitWindowsEx 2, 0
0
 
LVL 2

Author Comment

by:forrest321
ID: 11884692
It says: Name "exitWindowsEx" is not declared.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11884877
Sorry it is a typo, missing s:

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

ExitWindowsEx 2, 0
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11884902
Some refinements:

In Vb.net declaration could be simpler:
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

To ensure will reboot you can use:
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)

0
 
LVL 2

Author Comment

by:forrest321
ID: 11884936
That is compiling with no errors, but its not rebooting....
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11884976
What OS? Maybe you don't have privileges.
0
 
LVL 2

Author Comment

by:forrest321
ID: 11884989
Win XP Pro.  I am local and domain admin...privileges should be fine.
0
 
LVL 2

Author Comment

by:forrest321
ID: 11885768
Desp, I do not quite understand that source, or how to use it.  Have you used that before?
0
 
LVL 2

Assisted Solution

by:kHSw
kHSw earned 25 total points
ID: 11891191
These are the API declarations for VB6

You have to replace Long with Integer (Integer is 32 bits in .NET, the same as a Long in VB6):
Private Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Integer, ByVal  dwReserved As Integer) As Integer


Then put this into your code:
Public Const EWX_LOGOFF As Short = 0
Public Const EWX_SHUTDOWN As Short = 1
Public Const EWX_REBOOT As Short = 2
Public Const EWX_FORCE As Short = 4

ExitWindowsEx(EWX_FORCE, 0)


0
 
LVL 2

Expert Comment

by:kHSw
ID: 11891244
Just a little typo in my previous post.

You have to call ExitWindowsEx(EWX_SHUTDOWN)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11892029
Actually correct call to reboot must be:
ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
0
 
LVL 2

Author Comment

by:forrest321
ID: 12007389
I ended up using Shutdown.exe via shell call.

Thanks for the help.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now