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

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top