Hello Avi,
Did you try to look in MSDN for the info how to use WMI (Management namespace)
and try to convert my script to C#?
It takes less than 5 mins for this (sample in MSDN is available, you need
only point correct query and method)
//Connect to the remote computer
System.Management.ManagementScope ms = new ManagementScope("\\\\<your_server_name>\\root\\cim v2");
ms.Connect();
//Query remote computer across the connection
System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT
* FROM Win32_OperatingSystem");
ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms,
oq);
ManagementObjectCollection queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)
{
string[] ss ={ "" };
mo.InvokeMethod("Reboot", ss);
Console.WriteLine(mo.ToString());
}
AG> i'm looking for the code in C# for reboot machine...
AG>
AG> "Michael Nemtsev" wrote:
AG>
Hello Avi,
Use WMI for this, it's natural way
Sub RebootComputer( strServer )
Set objOSSet = GetObject("winmgmts:{(RemoteShutdown)}//" & strServer
& "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where
Primary=true")
For each objOS in objOSSet
objOS.Reboot()
Next
End Sub
AG> Hi,
AG>
AG> what is the quick code in C# for reboot local machine?
AG>
AG> Thanks.
AG>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog:
http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche