Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
How to restart and shutdown remote server in c#?
Shalu Shalini
May 29 2017 8:15 AM
431
Reply
Can anybody help to shutdown or restart the remote server using c#..
ManagementScope scope = new ManagementScope();
try
{
//get the credentials to connect to this computer with
ConnectionOptions options = new ConnectionOptions();
options.Username = "******";
options.Password = "xxxxxxxxxx";
options.EnablePrivileges = true;
options.Impersonation = ImpersonationLevel.Delegate;
options.Authority = "ntlmdomain:host.getkitaholic.com";
//Create the scope that will connect to the default root for WMI
scope = new ManagementScope(@"\\IP\root\CIMV2", options);
scope.Connect();
SelectQuery query = new SelectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
using (ManagementObjectCollection queryCollection = searcher.Get())
{
foreach (ManagementObject m in queryCollection)
{
string[] ss = { "" };
m.InvokeMethod("Reboot", ss);
}
}
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show("Unable to connect – Access is denied for those credentials"); return;
}
catch (Exception ex)
{
MessageBox.Show("Unable to connect due to an error: "); return;
}
here returns
RPC is UNAVAILABLE .. i dont know what i missed pls review the code or give me new solution
Thanks in advance
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
facing problem in navigation
Convert sqlquery to RowFilter DataTable Query