I apologies first as it might seem duplicate question. But I did a lot google even I reached two very similar one like:
But unfortunately none of them is working for me.
I have developed a windows service which runs on a windows server 2008 R2 standard machine.
Service is running very well and working nice as it should work.
My issue is I want to make a desktop application which will run on our local network. From this application I want to do some basic operation like getting getting service status, stopping and restarting.
Here is my work around.
private void WSControllerForm_Load(object sender, System.EventArgs e)
{
ConnectionOptions options = new ConnectionOptions();
options.Password = "password";
options.Username = "Administrator";
options.Impersonation =
System.Management.ImpersonationLevel.Impersonate;
options.EnablePrivileges = true;
options.Authority = "NTLMDOMAIN:IQ-HOME";
options.Authentication = AuthenticationLevel.PacketPrivacy;
ManagementScope scope =
new ManagementScope(@"\\RTOKEN-SERVER\root\cimv2", options);
scope.Connect(); //checked its connected
// Make a connection to a remote computer.
// Replace the "FullComputerName" section of the
// string "\\\\FullComputerName\\root\\cimv2" with
// the full computer name or IP address of the
// remote computer.
ServiceController service = new ServiceController("Recharger Token", "RTOKEN-SERVER");
service.Refresh();
MessageBox.Show(service.Status.ToString()); //Error raised: {"Cannot open Service Control Manager on computer 'rToken-server'. This operation might require other privileges."}
}
Please let me know am I doing some mistake? How should I achieve my goal?
NB: My development PC is Windows 7 Ultimate where as service is laying on Windows Server 2008 R2 Standard. Service is Running under Network Service. (I changed it to Administrator logon as well but no luck)
Thanks