Solved

VB.NET force reboot

Posted on 2004-08-24
13
697 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

828 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