Solved

Shutdown / reboot windows with VB.NET

Posted on 2004-04-13
10
539 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

13 Experts available now in Live!

Get 1:1 Help Now