Solved

Shutdown / reboot windows with VB.NET

Posted on 2004-04-13
10
554 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 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
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

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…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

627 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