0

I'm trying to set the path for a ManagementObject from user input to retrieve a remote computers battery information. I'm not sure this is even possible. I'm thinking this may have to be a separate program that dumps the information to a text file, then read the text file into the rich textbox on the form. Let me know what other information you need

    public StringBuilder Battery_Info(string PC_Name)
    {
        string caseAnswer = "";
        int timeAnswer = 0;
        PC_Name = PC_Name.ToUpper();

        SelectQuery Sq = new SelectQuery("Win32_Battery");
        ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);
        ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
        StringBuilder sb = new StringBuilder();

        foreach (ManagementObject mo in osDetailsCollection)
        {

// What I've tried ManagementObject mo = new ManagementObject("\\" + PC_Name + "\root\cimv2");

            switch ((ushort)mo["Availability"])
            {
                case 1:
                    caseAnswer = "Other";
                    break;
                case 2:
                    caseAnswer = "Unknown";
                    break;
                case 3:
                    caseAnswer = "Running/Full Power";
                    break;
                case 4:
                    caseAnswer = "Warning";
                    break;

etc, etc.

Thanks,

-J

JMJ
  • 35
  • 6
  • Use the WMI Code Creator utility to experiment, debug queries and generate C# code. Click the Target Computer menu item to try remote queries, shows how to use the ManagementScope class. – Hans Passant Feb 22 '21 at 17:16
  • See the two initialization procedures (`GetConnectionOptions()` and `GetEnumerationOptions()`) here: [Get the serial number of USB storage devices in .Net Core 2.1](https://stackoverflow.com/a/51806262/7444103) – Jimi Feb 22 '21 at 17:41

0 Answers0