You can try these codes for remotely shut down or restart a system within in a network...
ConnectionOptions co = new ConnectionOptions(); co.Username = "username"; co.Password = "****"; System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\" + ip + "\\root\\cimv2", co);
//Query remote computer across the connection System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem");//This is WMI query ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms, oq); ManagementObjectCollection queryCollection1 = query1.Get(); foreach (ManagementObject mo in queryCollection1) { string[] ss = { "" }; mo.InvokeMethod("Reboot", ss); //this 4 restart the remote system //mo.InvokeMethod("shutdown", ss); // this 4 shut down the remote system. Console.WriteLine(mo.ToString()); }
Wmi allows you to monitor virtually every system which are in your net work.WMI consists of several pieces that allow it to manage systems. All parts of the operating system are managed through COM by a provider that talks to WMI.
lijupnandana...
Member
80 Points
48 Posts
Remote system Shut down/ Restart
Mar 05, 2012 08:34 AM|LINK
You can try these codes for remotely shut down or restart a system within in a network...
ConnectionOptions co = new ConnectionOptions();
co.Username = "username";
co.Password = "****";
System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\" + ip + "\\root\\cimv2", co);
//Query remote computer across the connection
System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem");//This is WMI query
ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms, oq);
ManagementObjectCollection queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)
{
string[] ss = { "" };
mo.InvokeMethod("Reboot", ss); //this 4 restart the remote system
//mo.InvokeMethod("shutdown", ss); // this 4 shut down the remote system.
Console.WriteLine(mo.ToString());
}
Thanks,
lijupnandanan
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 08:59 AM|LINK
can you give the complete code here.....
is any other reference required?
MCP
vijayano
Member
162 Points
51 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 09:04 AM|LINK
Hello,
Is the above code fully working?
lijupnandana...
Member
80 Points
48 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 09:20 AM|LINK
Yep.. These codes are working.. i used this codes in my web application and working perfectly.. I tried thses in windows 7 and Xp...
Its working...
lijupnandana...
Member
80 Points
48 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 09:21 AM|LINK
These are the complte codes.... you need to add "using System.Management;" Library name on the code page..
thats all..
Thanks,
lijupnandanan
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 09:33 AM|LINK
ca nyou explain
System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\" + ip + "\\root\\cimv2", co);how you have build the path?
MCP
lijupnandana...
Member
80 Points
48 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 09:43 AM|LINK
Hi,
WMI (Windows Management Instrumentation) is a component of the Microsoft operating system.
You can refer " http://msdn.microsoft.com/en-us/library/system.management.managementscope.aspx "
"http://www.c-sharpcorner.com/UploadFile/mgold/MonitoringRemoteLogusingWMI11232005020152AM/MonitoringRemoteLogusingWMI.aspx"
Wmi allows you to monitor virtually every system which are in your net work.WMI consists of several pieces that allow it to manage systems. All parts of the operating system are managed through COM by a provider that talks to WMI.
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 09:49 AM|LINK
nice code, it works perfectly for me.
MCP
anildob84
Member
226 Points
95 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 09:52 AM|LINK
This is working fine!!!!
Visit for more details: http://aspdotnetblogspot.blogspot.in/2012/02/dropdownlist-in-aspnet-using-c.html
Thanks,
lijupnandana...
Member
80 Points
48 Posts
Re: Remote system Shut down/ Restart
Mar 05, 2012 09:57 AM|LINK
Hi,
You can also try this commands.. in which you need to manually enter the username and password...
System.Diagnostics.Process.Start("ShutDown", "-i"); //in c# code
or typ shutdown -i in run or in command prompt...
you cxan try these commands too...
ShutDown -s -m
ShutDown -m
thanks,
lijupnandanan