How do I set the path for a ManagementObject?

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";
                case 2:
                    caseAnswer = "Unknown";
                case 3:
                    caseAnswer = "Running/Full Power";
                case 4:
                    caseAnswer = "Warning";

etc, etc.



Read more here:

Content Attribution

This content was originally published by JmJ at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: