wmi to access the services runnig in PC ? -error help required

  • Thread starter Thread starter myclassmates
  • Start date Start date
M

myclassmates

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: The RPC server is unavailable.

See the code below and help me out to solve this problem.

public static void Main(string[] args)
{
string strvalue;
Console.WriteLine("Welcome to Ansync webservice application");
ManagementObject Status;
Status= new ManagementObject(null,new
ManagementPath("//server/root/cimv2:Win32_Service.Name='MSSQLServer'"),null);

Console.WriteLine(Status["Started"].ToString());
Status.Dispose();

Console.ReadLine();

}

I need to print started if SQLServer has started or stopped otherwise
 
Care to point out WHICH line it occured on?

On top of that, are you getting this in your console application? Or
are you getting this in an ASP.NET web service? While your code is for a
console app, the first call to WriteLine is dubious.

If you are running this in ASP.NET, then by default, you are running
under the ASPNET account, which doesn't have access to the machine you are
trying to connect to, most likely.

Hope this helps.
 
myclassmates said:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: The RPC server is unavailable.

See the code below and help me out to solve this problem.

public static void Main(string[] args)
{
string strvalue;
Console.WriteLine("Welcome to Ansync webservice application");
ManagementObject Status;
Status= new ManagementObject(null,new
ManagementPath("//server/root/cimv2:Win32_Service.Name='MSSQLServer'"),null);

Console.WriteLine(Status["Started"].ToString());
Status.Dispose();

Console.ReadLine();

}

I need to print started if SQLServer has started or stopped otherwise

It's fundamental to read the docs before you start coding, your
managementpath is wrong!

("//server/root/cimv2:Win32_Service.Name....

should read:

(@"\\server\root\cimv2:Win32_Service.Name...

Note the @ the \\ and the \ !

Willy.
 
Back
Top