?
Solved

VB.NET force reboot

Posted on 2004-08-24
13
Medium Priority
?
708 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 19

Assisted Solution

by:Fahad Mukhtar
Fahad Mukhtar earned 100 total points
ID: 11882347
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 200 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 100 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Simple Linear Regression
Progress
Suggested Courses

800 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