Remotely restart the computer (C #)

Source: Internet
Author: User
Remotely restart the computer (C #)
First, add a reference to system. Management.
Then CodeEntry:
Connectionoptions op = new connectionoptions ();
Op. Username = "wgscd"; 'or your account (Be sure to have administrator privileges)
Op. Password = "wgscd"; 'your password
Managementscope scope = new managementscope ("\\\\" + "106.54.20.1" + "\ Root \ wgscd ",

OP );
Try
{
Scope. Connect ();
System. Management. objectquery OQ = new system. Management. objectquery ("select * from

Win32_operatingsystem ");
Managementobjectsearcher query1 = new managementobjectsearcher (scope, OQ );
// Obtain WMI Control
Managementobjectcollection querycollection1 = query1.get ();

Foreach (managementobject mobj in querycollection1)
{
String [] STR = {""};
Mobj. invokemethod ("reboot", STR );
}
}
Catch
{

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.