Sub RebootComputer( strServer )
Set objOSSet = GetObject("winm gmts:{(RemoteSh utdown)}//" & strServer
& "/root/cimv2").ExecQue ry("select * from Win32_Operating System 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
i'm looking for the code in C# for reboot machine...
"Michael Nemtsev" wrote:
[color=blue]
> Hello Avi,
>
> Use WMI for this, it's natural way
>
> Sub RebootComputer( strServer )
> Set objOSSet = GetObject("winm gmts:{(RemoteSh utdown)}//" & strServer
> & "/root/cimv2").ExecQue ry("select * from Win32_Operating System 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
>
>
>[/color]
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.Manageme nt.ManagementSc ope ms = new ManagementScope ("\\\\<your_ser ver_name>\\root \\cimv2");
ms.Connect();
//Query remote computer across the connection
System.Manageme nt.ObjectQuery oq = new System.Manageme nt.ObjectQuery( "SELECT
* FROM Win32_Operating System");
foreach (ManagementObje ct mo in queryCollection 1)
{
string[] ss ={ "" };
mo.InvokeMethod ("Reboot", ss);
Console.WriteLi ne(mo.ToString( ));
}
AG> i'm looking for the code in C# for reboot machine...
AG>
AG> "Michael Nemtsev" wrote:
AG>[color=blue][color=green]
>> Hello Avi,
>>
>> Use WMI for this, it's natural way
>>
>> Sub RebootComputer( strServer )
>> Set objOSSet = GetObject("winm gmts:{(RemoteSh utdown)}//" & strServer
>> & "/root/cimv2").ExecQue ry("select * from Win32_Operating System 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
>>[/color][/color]
---
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
Hi Avi,
[color=blue]
> what is the quick code in C# for reboot local machine?[/color]
Unfortunately, there's no "one-liner" that you could call in C# to reboot
the machine. Instead, it is a little bit more complex due to special
privileges you will need. The Win32 API function to reboot the machine is
ExitWindowsEx. See this page for details:
Choosing the right web hosting company is one of the most important — and most consequential — decisions you’ll make when starting or growing your website.
[color=blue][color=green]
>> what is the quick code in C# for reboot local machine?
>>[/color][/color]
J> Unfortunately, there's no "one-liner" that you could call in C# to
J> reboot the machine. Instead, it is a little bit more complex due to
J> special privileges you will need. The Win32 API function to reboot
J> the machine is ExitWindowsEx. See this page for details:
J>
J> http://msdn.microsoft.com/library/de...ary/en-us/shut
J> down/base/exitwindowsex.a sp
J>
J> Now, to the C# code. There is the direct P/Invoke route, and the WMI
J> route that Michael Nemtsev pointer out. Try this page for tips:
J>
J> http://www.dotnet247.com/247reference/msgs/9/49583.aspx
"Avi G" <AviG@discussio ns.microsoft.co m> wrote in message
news:0A3F1041-2BCE-40AE-A19D-5576D5402AD5@mi crosoft.com...[color=blue]
>
> what is the quick code in C# for reboot local machine?[/color]
Reminds me of the good old days, when you could write REBOOT.COM (using DOS
DEBUG) in a couple of asm statements...
"Mark Wilden" <MarkWilden@new sgroups.nospam> wrote in message
news:eu4gVh0hGH A.4864@TK2MSFTN GP05.phx.gbl...
[color=blue]
> "Avi G" <AviG@discussio ns.microsoft.co m> wrote in message
> news:0A3F1041-2BCE-40AE-A19D-5576D5402AD5@mi crosoft.com...[color=green]
>>
>> what is the quick code in C# for reboot local machine?[/color]
>
> Reminds me of the good old days, when you could write REBOOT.COM (using
> DOS DEBUG) in a couple of asm statements...[/color]
:-) I still have a copy of that on an old floppy disk somewhere... :-)
"Jani Järvinen [MVP]" <janij@removeth is.dystopia.fi> wrote in message
news:OK$aZpwhGH A.1320@TK2MSFTN GP04.phx.gbl...
| Hi Avi,
|
| > what is the quick code in C# for reboot local machine?
|
| Unfortunately, there's no "one-liner" that you could call in C# to reboot
| the machine. Instead, it is a little bit more complex due to special
| privileges you will need. The Win32 API function to reboot the machine is
| ExitWindowsEx. See this page for details:
|
|
Comment