2

For the following code, I am getting

System.ComponentModel.Win32Exception: The network path was not found

Can anyone help?

PerformanceCounter pc = new PerformanceCounter("System",
        "System Up Time");
                pc.MachineName = "1.2.3.4";

                //Normally starts with zero. do Next Value always.
                pc.NextValue();
                TimeSpan ts = TimeSpan.FromSeconds(pc.NextValue());

                Response.Write("This system 1.2.3.4 has been up for " + ts.Days + " days " + ts.Hours + " hours, " + ts.Minutes + " and " + ts.Seconds +" seconds.");

Edit: I tried with machine name, and I still get the same error! Note: 1.2.3.4 is a sample value.

bluish
  • 26,356
  • 27
  • 122
  • 180
genericuser
  • 1,430
  • 4
  • 22
  • 40
  • 3
    Perhaps you just don't have any machine with 1.2.3.4 as its name? It looks like an example value, which you might have to change appropriately. – pimvdb Jan 24 '11 at 18:39
  • yeah thats the sample ip address, I did not put the actual value. – genericuser Jan 24 '11 at 19:04

4 Answers4

11

This error can be caused if the Remote Registry service is not started on the remote machine 1.

nftw
  • 589
  • 4
  • 10
2

Uncomment pc.NextValue() and the code works. The problem is reproduceable by giving a bad machine name or IP address. So your IP is bad.

var machineNameOrIP = "10.16.7.1";
var pc = new PerformanceCounter("System", "System Up Time");
pc.MachineName = machineNameOrIP;
//Normally starts with zero. do Next Value always.
pc.NextValue();//uncomment this
var ts = TimeSpan.FromSeconds(pc.NextValue());
Response.Write("This system " + pc.MachineName + " has been up for " + ts.Days + " days " + ts.Hours + " hours, " + ts.Minutes + " and " + ts.Seconds +" seconds.");
bluish
  • 26,356
  • 27
  • 122
  • 180
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
  • no, the IP is not bad, I tried to ping it, and it works. pc.NextValue() is the place where it fails and gives "The network path was not found". "1.2.3.4 is sample ip that I put in the above code sample" – genericuser Jan 24 '11 at 19:03
  • 4
    At least 3 of us have run the code and the code works. I'm running Windows XP SP3. Its something with your environment. Permissions, OS configuration, network..etc. This forum is for code issues. Walk over to the machine make sure its running a windows OS, you have the right IP, run systeminfo make sure it returns the uptime, check with netOps...these are your next steps and these arent code steps. – P.Brian.Mackey Jan 24 '11 at 19:16
0

Either the MachineName "1.2.3.4" does not exist, or it cannot be reached on the network.

I tested your code with a machine name that exists on my network, and it works fine.

driis
  • 161,458
  • 45
  • 265
  • 341
0

More than likely the MachineName value that you are using is not a machine that can be found on the network. i would start with that and validate that you are able to connect to it.

Mitchel Sellers
  • 62,228
  • 14
  • 110
  • 173