Solved

VB.NET force reboot

Posted on 2004-08-24
13
691 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
noX challenge 17 91
How does Google get such fast response times? 5 151
tidtcpserver connection lost handle 2 70
parse convert xml feed to text (python) 2 69
A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

22 Experts available now in Live!

Get 1:1 Help Now