473,379 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to shut down computer using VB .NET

Won
I want to know how to shut down computer using VB .NET. Thank you
Nov 20 '05 #1
5 15201
Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\LocalHost\roo t\cimv2")
ms.Options.EnablePrivileges = True
' Verwende diesen Eigenschaften wenn es Probleme mit den Rechten gibt
'ms.Options.Password = ""
'ms.Options.Username = ""
Dim oq As System.Management.ObjectQuery = New System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem")
Dim query1 As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher(ms, oq)
Dim queryCollection1 As System.Management.ManagementObjectCollection = query1.Get()
For Each mo As System.Management.ManagementObject In queryCollection1
Dim ss As String() = {"2", "0"} ' Reboot
'Dim ss As String() = {"2", "2"} ' Logoff
'Dim ss As String() = {"0", "0"} ' Shutdown
mo.InvokeMethod("Win32Shutdown", ss)
Next
Nov 20 '05 #2
* =?Utf-8?B?V29u?= <an*******@discussions.microsoft.com> scripsit:
I want to know how to shut down computer using VB .NET. Thank you


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

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
I put your code

Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\LocalHost\roo t\cimv2"
Dim mo As System.Management.ManagementObjec

ms.Options.EnablePrivileges = Tru

' Verwende diesen Eigenschaften wenn es Probleme mit den Rechten gib
'ms.Options.Password = "
'ms.Options.Username = "

Dim oq As System.Management.ObjectQuery = New System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem"
Dim query1 As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher(ms, oq
Dim queryCollection1 As System.Management.ManagementObjectCollection = query1.Get(

For Each mo In queryCollection
'Dim ss As String() = {"2", "0"} ' Reboo
'Dim ss As String() = {"2", "2"} ' Logof
Dim ss As String() = {"2", "0"} ' Shutdow
mo.InvokeMethod("Win32Shutdown", ss
Nex

but gives me this message...."PREVILEGE NOT HELD"...Why is that?
Nov 20 '05 #4
Cor
Hi Nuno,
but gives me this message...."PREVILEGE NOT HELD"...Why is that? I do not know, but did you read this
' Verwende diesen Eigenschaften wenn es Probleme mit den Rechten gibt 'ms.Options.Password = ""
'ms.Options.Username = ""


(It is not my language, but there is written).

Use this properties when there are problems with the privileges.
I think he means
Use this rows with the properties set as shown when there are problems with
the privileges

Cor
Nov 20 '05 #5
Hi,

In addition to Cor's comments. Here is a link to a class which will
shutdown windows.
http://www.mentalis.org/soft/class.qpx?id=7

Ken
-------------------
"Nuno" <Nu********@Inforbase.PT> wrote in message
news:11**********************************@microsof t.com...
I put your code :

Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\LocalHost\roo t\cimv2") Dim mo As System.Management.ManagementObject

ms.Options.EnablePrivileges = True

' Verwende diesen Eigenschaften wenn es Probleme mit den Rechten gibt 'ms.Options.Password = ""
'ms.Options.Username = ""

Dim oq As System.Management.ObjectQuery = New System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem") Dim query1 As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher(ms, oq) Dim queryCollection1 As System.Management.ManagementObjectCollection = query1.Get()
For Each mo In queryCollection1
'Dim ss As String() = {"2", "0"} ' Reboot
'Dim ss As String() = {"2", "2"} ' Logoff
Dim ss As String() = {"2", "0"} ' Shutdown
mo.InvokeMethod("Win32Shutdown", ss)
Next

but gives me this message...."PREVILEGE NOT HELD"...Why is that?

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
1
by: Daniel | last post by:
System.IO.StreamWriter Close or Flush method to shut down the computer in such a way that just part of the file is written? or an empty file is written? Also if the Close or Flush is to a...
2
by: Jesper DK | last post by:
Hi, I would like a program invoked when the computer is shut down or a user logs off. Is there a fix way of doing this. I uses the startup folder to run the program, but I need to run it when...
5
by: Anders Both | last post by:
If no pages in my asp.net web-system, is being requested for some periode, it seems like the asp.net process is shut down automaticaly. Is this a normal behavior, or does my system contains some...
0
by: Stephen | last post by:
Hi, I am trying to copy files from one computer to another, the problem I am facing is that the program chokes when the other computer is not available (shut down/off the n/w). is there any way...
1
by: =?Utf-8?B?bWl0cmVib3g=?= | last post by:
Ever since I loaded Office 2007 and Avast Anti-Virus, I cannot get Windows XP Professional to shut down and turn the computer off. I have to push and hold the On/Off for several seconds to turn...
6
sashi
by: sashi | last post by:
Shut down Windows For various reasons you may require a shut down of Windows to happen programmatically. For instance if the installation of your program requires system reconfiguration. The...
2
by: Dinesh kamath | last post by:
please give me the code for shut down a computer using network but i dont have server but we have lan connection
2
by: shaif | last post by:
Hi all, I try to shut down computer for security module developemnt. I used the following code, But its doesnt work also no error message come, Could you please clarify whicj way I can proceed? Thx a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.