Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shutdown / reboot windows with VB.NET

Posted on 2004-04-13
10
Medium Priority
?
556 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
[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
  • 2
  • 2
  • 2
  • +2
10 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 500 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 500 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
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 500 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 500 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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