TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shalu Shalini
NA
123
16.8k
How to restart and shutdown remote server in c#?
May 29 2017 8:15 AM
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
Reply
Answers (
5
)
facing problem in navigation
Convert sqlquery to RowFilter DataTable Query