Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Dynamically retrieving WMI Data - A little help please!

Dynamically retrieving WMI Data - A little help please!

Scheduled Pinned Locked Moved C#
csharpdatabasehelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    junus
    wrote on last edited by
    #1

    Hi there, i get an exception while using C# and wmi to retrieve some data. So here is the code is wrote: public class Adapter { public static ManagementObjectCollection GetNicAdapters() { try { WqlObjectQuery WQO = new WqlObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus != null"); ManagementObjectSearcher MOS = new ManagementObjectSearcher(WQO); ManagementObjectCollection MOC = MOS.Get(); return MOC; } catch (Exception ex) { MessageBox.Show("Data couldn't be retrieved."); return null; } } I use this function to populate a field in my Form1 Base form. On the form (visually) there is a combo box, which now is filled with the Description of the Object. All of this works so far but now i am getting problems: private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (Adapters != null) { try { ManagementObject[] MOArray = new ManagementObject[Adapters.Count]; Adapters.CopyTo(MOArray, 0); int select = comboBox1.SelectedIndex; int selectedIndex = int.Parse(MOArray[select]["Index"].ToString()); int status = int.Parse(MOArray[select]["NetConnectionStatus"].ToString()); string myQueryString = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " + selectedIndex.ToString(); WqlObjectQuery ConfigQuery = new WqlObjectQuery(myQueryString); ManagementObjectSearcher ConfigSearcher = new ManagementObjectSearcher(ConfigQuery); ManagementObjectCollection ManagementObjectConfigurations = ConfigSearcher.Get(); ManagementObject[] CurrentArray = new ManagementObject[ManagementObjectConfigurations.Count]; ManagementObjectConfigurations.CopyTo(CurrentArray, 0); ManagementObject CurrentConfig = CurrentArray[0]; #region Draw Status IconConverter IC = new IconConverter(); switch (status) { case 0: l_status.Text = "Gerät nicht angeschlossen";

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups