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. WMI Events can't get User | ManagementEventWatcher, __INstanceCreationEvent, Win32_Process GetOwner

WMI Events can't get User | ManagementEventWatcher, __INstanceCreationEvent, Win32_Process GetOwner

Scheduled Pinned Locked Moved C#
databasewindows-adminhelptutorial
3 Posts 2 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.
  • M Offline
    M Offline
    Member 13022244
    wrote on last edited by
    #1

    Ultimately I wish to have my app watch for any new processes recording the command line and the owner. I can get the processID, Name, and CommandLine without any issues however since the ManagementEventWatcher returns a ManagementBaseObject and not a ManagementObject (which has a method for .GetOwner) I cannot seem to get the owner. What I have tried. - I looked through the properties of the ManagementBaseObject, no method for GetOwner or a property for User. - I pulled the ProcessID from the ManagementBaseObject (mboEvent["TargetInstance"])["ProcessID"].ToString(). This works as I can get a ManagementObject and then use GetOwner... The second item does work except that it only works on a slower command (for example Powershell.exe Get-Process) as the process still exists at the time of the query. But quicker commands (like net use or powershell.exe get-services) don't return a username as the process is gone by the time I query for it. Any help would be amazing, thanks in advance for any help you can give.

    M 1 Reply Last reply
    0
    • M Member 13022244

      Ultimately I wish to have my app watch for any new processes recording the command line and the owner. I can get the processID, Name, and CommandLine without any issues however since the ManagementEventWatcher returns a ManagementBaseObject and not a ManagementObject (which has a method for .GetOwner) I cannot seem to get the owner. What I have tried. - I looked through the properties of the ManagementBaseObject, no method for GetOwner or a property for User. - I pulled the ProcessID from the ManagementBaseObject (mboEvent["TargetInstance"])["ProcessID"].ToString(). This works as I can get a ManagementObject and then use GetOwner... The second item does work except that it only works on a slower command (for example Powershell.exe Get-Process) as the process still exists at the time of the query. But quicker commands (like net use or powershell.exe get-services) don't return a username as the process is gone by the time I query for it. Any help would be amazing, thanks in advance for any help you can give.

      M Offline
      M Offline
      Michael_Davies
      wrote on last edited by
      #2

      Try casting the managementbaseobject as managementobject, often works. Example at : wmi - Convert .Net ManagementBaseObject to ManagementObject - Stack Overflow[^]

      M 1 Reply Last reply
      0
      • M Michael_Davies

        Try casting the managementbaseobject as managementobject, often works. Example at : wmi - Convert .Net ManagementBaseObject to ManagementObject - Stack Overflow[^]

        M Offline
        M Offline
        Member 13022244
        wrote on last edited by
        #3

        Brilliant ! Thank you so much for the quick response. You saved me hours. I very much appreciate it.

        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