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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. WMI and C#

WMI and C#

Scheduled Pinned Locked Moved C#
questioncsharpsysadmin
3 Posts 3 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.
  • B Offline
    B Offline
    Bo Hunter
    wrote on last edited by
    #1

    I need a way to get network status like connected or disconnected. I have generated a class with mgmtclassgen and it throws exceptions when tring to create the class. What is the best way to do this? Thank you Bo Hunter Me

    D T 2 Replies Last reply
    0
    • B Bo Hunter

      I need a way to get network status like connected or disconnected. I have generated a class with mgmtclassgen and it throws exceptions when tring to create the class. What is the best way to do this? Thank you Bo Hunter Me

      D Offline
      D Offline
      David Stone
      wrote on last edited by
      #2

      Are you using the System.Management and System.Management.Instrumentation namespaces? If so, then you can just use a WQL query with the ManagementQuery object and query whatever you want.


      Hey, what can I say? I'm a chick magnet...a babe conductor...a logarithm for the ladies. -Strong Bad from HomeStarRunner.com Essential Tips for Web Developers

      1 Reply Last reply
      0
      • B Bo Hunter

        I need a way to get network status like connected or disconnected. I have generated a class with mgmtclassgen and it throws exceptions when tring to create the class. What is the best way to do this? Thank you Bo Hunter Me

        T Offline
        T Offline
        thematt
        wrote on last edited by
        #3

        I am assuming you are using WMI to get the network status. The problem you may be that certain adapters do not have an actual instance when you check the status. For example the WAN Miniport (PPTP) will not have a status all the time (if it does at all). WHen you loop through your ManagementCollection you will get a NullReferenceException - Bo Hunter wrote: object ref not set to an instance object ref not set to an instance. To get around this you should catch the error, or narrow your WQL. If there is a certain adapter you are checking for let me know. I will post some code. I hope this is along the lines of what you are after. Matt is a network administrator for an insurance company in the midwest. He is shamelessly looking for Windows programming side work.

        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