How to shut down computer using VB .NET

  • Thread starter Thread starter Guest
  • Start date Start date
Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\LocalHost\root\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
 
I put your code

Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\LocalHost\root\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?
 
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
 
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 said:
I put your code :

Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\LocalHost\root\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()
 
Back
Top