Solved

Shut Down win Xp vb.net 2008

Posted on 2009-05-07
10
451 Views
Last Modified: 2013-11-26
i need vb.net 2008 code to shut down win xp
0
Comment
Question by:aarontham
[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
10 Comments
 
LVL 5

Expert Comment

by:drakeshe
ID: 24323078
Shutdown, Restart, or Log Off your computer using VB.Net
    Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click
        System.Diagnostics.Process.Start("shutdown", "-s -t 00")
        'This will make the computer Shutdown
    End Sub
 
    Private Sub btnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestart.Click
        System.Diagnostics.Process.Start("shutdown", "-r -t 00")
        'This will make the computer Restart
    End Sub
 
    Private Sub btnLogOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogOff.Click
        System.Diagnostics.Process.Start("shutdown", "-l -t 00")
        'This will make the computer Log Off
    End Sub
 
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        End
        'This will make the program to terminate(end the program)
    End Sub

Open in new window

0
 
LVL 7

Expert Comment

by:thiyaguk
ID: 24323113
0
 
LVL 5

Expert Comment

by:drakeshe
ID: 24323124
oh ya, forgot lol. =/
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24323128
that was blazingly fast, drakeshe!

Instead of using the shutdown.exe tool (which, iirc, is not available on older windows, but then again, older windows are rare) you can do this through Win32Shutdown method of WMI as follows, which has the benefit of being able to get information when the shutdown does not succeed:

Dim response As Single
Dim objWMIService, objComputer As Object
 
'Now get some privileges '
objWMIService = GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")
 
For Each objComputer In objWMIService.InstancesOf("Win32_OperatingSystem")
 
   ' 1 + 4 is a forced shutdown, 1 is a normal shutdown '
   response = objComputer.Win32Shutdown(1 + 4, 0)
 
   If response <> 0 Then
      MsgBox("Something wrong")
   Else
 
   End If
Next

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24327845
Tx for the grade & pts, but...

if you don't comment on why you accept one solution over another, while another is still a
viable alternative, it is a common use at EE to split the points. See the closing q. guidelines.
0
 

Author Comment

by:aarontham
ID: 24328052
drakeshe solution don't work on win XP
0
 
LVL 39

Expert Comment

by:abel
ID: 24328347
ah, ok. Didn't know that, tx for letting us in it ;)
0
 
LVL 5

Expert Comment

by:drakeshe
ID: 24330907
It does work on Windows XP, but perhaps you do not have proper permissions. If the methods are controlled by permissions then it may not be a good solution
0
 
LVL 39

Expert Comment

by:abel
ID: 24331564
interesting point, but the permissions are just as needed when you use the WMI method. The only difference may be that you can interrogate the return value to find out why restarting / shutting down didn't work.

But there's something else with shutdown.exe, or with any other Process.Start. More and more restrictions are applied on starting other processes. More firewalls bug users with messages "do you allow this process X to start this other process Y". It is for the good, but sometimes it is working quite too much against us.
0
 
LVL 5

Expert Comment

by:drakeshe
ID: 24331652
I've heard of anti-viruses that disabled .exe files that aren't installed into c:\program files\*  XD
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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