Error on some computers when trying to capture processor voltage by WMI

Asked

Viewed 27 times

0

On only a few computers while running my hardware specification program it accuses an error on the 155 line.

public static String voltage()
            {
                String Ic = String.Empty;
                foreach (var item in new ManagementObjectSearcher("Select from Win32_Processor").Get())
            {
                   Ic = (decimal.Parse(item["CurrentVoltage"].ToString()) / 10).ToString() + " v";
                    if(Ic == "0")
                    {
                        return "~";
                    }
                }
                return Ic;
            }

Line 155 below.

Ic = (decimal.Parse(item["CurrentVoltage"].ToString()) / 10).ToString() + " v";

And prevents my program from running normally but is only on some computers, in general the program runs without errors.

inserir a descrição da imagem aqui

  • Maybe administrator access on these computers?

  • Ricardo not because in other computers were also without administrator access.

  • What is the Exception launched? what is inside of details there? It pastes there in the question, it will help to try to find out

  • Apparently the line is causing an Exception that the code has not dealt with. It may be non existing in item, or its value is empty, etc., which may be caused by the lack of information. Check what type of processor and motherboard the system is running, run permissions and improve code by adding an exception treatment.

  • For me, the most likely error is item["Currentvoltage"] to be NULL! or item is null.

  • Ricardo unfortunately I will not be able to show the details because I am far from the computer that is giving the error, but when I clicked he informs that it is in Voltage() on line 155. Marcos Regis ok more so how can I add an exception treatment before giving error?

  • If you do not get access to machine with problems (I understand that is customer machine) then I would put a catch Try in the block and log, is not the solution, but you via manage to catch what is happening, null treatment that @Paulohdsousa can already be done before anything either.

  • 2

    @G.Carlo you should not add treatment to the exception, that is gambiarra, the thick one. You should fix the programming error present in the code. Which we can’t help for lack of information.

  • 2

    Voltages, fan speed and temperature rarely have interface exposed in WMI. Usually a third party software is required to expose this data. The few hardware combinations that have this information directly through windows are mere exceptions.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.