Solved

Shutdown / reboot windows with VB.NET

Posted on 2004-04-13
10
548 Views
Last Modified: 2011-08-18
Hi.
I am using VB.NET not VB6 !
---------------------------------
How do you shutdown or reboot Windows 2000 server, XP server 2003 server with Visual Basic .NET?

Ideally I need the following options:
- EWX_LogOff
- EWX_SHUTDOWN
- EWX_REBOOT
- EWX_FORCE
- EWX_POWEROFF

I need a working example please not just a description.

500 points.
Many thanks
0
Comment
Question by:gjok
  • 2
  • 2
  • 2
  • +2
10 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 125 total points
ID: 10816672


You'll need to use WinAPI for that, .Net does not handle that natively.

Here's a site that will help you:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/functions_by_category.asp


You'll probably want to use the Advapi32.lib:

BOOL InitiateSystemShutdownEx(
  LPTSTR lpMachineName,
  LPTSTR lpMessage,
  DWORD dwTimeout,
  BOOL bForceAppsClosed,
  BOOL bRebootAfterShutdown,
  DWORD dwReason
);


0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10816677

As for a sample... I've done this a few times in VB6 using the old method, I haven't actually tried it with the advanced libraries yet.  I'll have to get back to you on that one.
0
 
LVL 9

Assisted Solution

by:glsac
glsac earned 125 total points
ID: 10816687
Yup, no way in the framework...

http://www.mentalis.org/soft/class.qpx?id=7

Which seems to be down now has a class in .NET to do this using API...but again the site is down now.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Author Comment

by:gjok
ID: 10816817
Thanks _TAD_ ,glsac

glsac, I had previously downloaded this, but its just a couple of .vb files with no .sln file. How do I try it out. Also, is there a DLL or something to make the code work??

(I havn't quite got accustommed to .NET yet - still stuck in VB6 land)
gjok.
0
 
LVL 2

Author Comment

by:gjok
ID: 10817133
(Sorry for the above stupid comment. I see how it works now.)
0
 
LVL 28

Assisted Solution

by:iboutchkine
iboutchkine earned 125 total points
ID: 10817347
to shut down windows xp use shell "shutdown.exe -s" (shutdown) shell "shutown.exe -r" (reboot)
0
 
LVL 10

Assisted Solution

by:heintalus
heintalus earned 125 total points
ID: 10819448
Try this

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

    Public Enum Flags
        Logoff = 0
        Shutdown = 1
        Reboot = 2
        ForceLogOff = 4
        ForceReboot = 6
        PowerDown = 8
        ForcePowerDown = 12
    End Enum

    Public Sub ExitWindows(ByVal flag As Flags)
        ExitWindowsEx(flag, 0)
    End Sub

then where you want to call the exit windows function just call ExitWindows() with the appropriate flag for example to logoff you'd use
ExitWindows(Flags.Logoff)

HTH
Andy
0
 
LVL 9

Expert Comment

by:glsac
ID: 11086348
glsac, I had previously downloaded this, but its just a couple of .vb files with no .sln file. How do I try it out. Also, is there a DLL or something to make the code work??

(I havn't quite got accustommed to .NET yet - still stuck in VB6 land)
gjok.

 
Comment from gjok
Date: 04/13/2004 01:21PM PDT
 Author Comment  


(Sorry for the above stupid comment. I see how it works now.)
-------------------------------------
No matter...but I do think he got it to work with my link to a .net class file :)
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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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