does anyone have any idea on how to convert this to c#
Sub shutdown()
Dim t 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")
t = objComputer.Win32Shutdown(8 + 4, 0)
If t <> 0 Then
'Error occurred!!!
Else
'Shutdown your system
End If
Next
End Sub

vb to c# code conversion
Aaron Smith
no worries. We need to spin up a Process class and execute it. This allows us to pretty much "shell" or execute programs outside our application. So....
import the System.Diagnostics namespace. Then....
ProcessStartInfo theProc = new ProcessStartInfo("shutdown");
theProc.Arguments = "/m \\computerName /s";
Process.Start(theProc);
does this help
Demix
hi plz use a biger font for you code
i assume GetObject is a method in your project, and i don't know what you are trying to do, but i guess you used WMI so you need to add reference for System.Management to your project and to add "using System.Management" to your class, i don't know if you gonna need to use Microsoft.win32 namespace or not
hope this helps
Tollo
hi,
you can use converter to do that
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
hope this helps
mNilysg
sure you can. you can abort a shutdown/restart or logout action that is happening. the command to abort is:
shutdown /m \\computerName /a
and thats it! click start > run > cmd >
type: shutdown /
and this will give you all the options you can use for the shutdown utility
nobitavn94
this is a VB function, what i am trying to do is restart or shutdown a computer. If you know of a better way to do this
Public Function GetObject(Optional ByVal PathName As
String = Nothing, Optional ByVal Class As String = Nothing) As ObjectMember of:
Microsoft.VisualBasic.InteractionSummary:
Returns a reference to an object provided by a COM component.
Parameters:
PathName: Optional. String. The full path and name of the file containing the object to retrieve. If PathName is omitted, Class is required.
Class: Required if PathName is not supplied. String. A string representing the class of the object. The Class argument has the following syntax and parts:appname.objecttypeParameterDescriptionappnameRequired. String. The name of the application providing the object.objecttypeRequired. String. The type or class of object to create.
Return Values:
Returns a reference to an object provided by a COM component.
AboOmar
Bill Baker
mrplatypus
best way of doing so would be to use the shutdown utility in Windows 2000 and higher I believe.
shutdown /m \\computerName /s
would shutdown the computer. Placing a /r instead of /s will restart the computer
Bob Heitzman
i converted the code and these are the errors that i recieved when i tried to compile it
public void shutdown()
{
float t;
Object objWMIService;
Object objComputer;
objWMIService = GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}");
foreach (int objComputer in objWMIService.InstancesOf("Win32_OperatingSystem"))
{
t = objComputer.Win32Shutdown(8 + 4, 0);
if (t != 0)
{
}
else
{
}
}
}
error CS0103: The name 'GetObject' does not exist in the current contexterror CS0117: 'object' does not contain a definition for 'InstancesOf'
error CS0136: A local variable named 'objComputer' cannot be declared in this scope because it would give a different meaning to 'objComputer', which is already used in a 'parent or current' scope to denote something else
error CS0117: 'object' does not contain a definition for 'Win32Shutdown'