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. How to identify user, who runs a certain process?

How to identify user, who runs a certain process?

Scheduled Pinned Locked Moved C#
questiontutorial
2 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.
  • 3 Offline
    3 Offline
    3Dizard
    wrote on last edited by
    #1

    I use the Process.GetProcessesByName-Method to retreive all processes, having the same name. In certain circumstances this processes run under different users. How can I find out which user runs which process? Completely different methods than using System.Diagnostics.Process are also appreciated. Thanks.

    S 1 Reply Last reply
    0
    • 3 3Dizard

      I use the Process.GetProcessesByName-Method to retreive all processes, having the same name. In certain circumstances this processes run under different users. How can I find out which user runs which process? Completely different methods than using System.Diagnostics.Process are also appreciated. Thanks.

      S Offline
      S Offline
      Scott Serl
      wrote on last edited by
      #2

      You can get this info by using the System.Management namespace functions. I do not have an example in c#, but I have one in vb.net if you are interested. Basically: System.Management.ConnectionOptions con = new System.Management.ConnectionOptions; System.Management.ManagementScope mgmtScope = new System.Management.ManagementScope("\\localhost", con); System.Management.ObjectQuery objQuery = new System.Management.WqlObjectQuery("SELECT * FROM win32_process"); System.Management.ManagementObjectSearcher objSearch = new Management.ManagementObjectSearcher(mgmtScope, objQuery); System.Management.ManagementObjectCollection objCol = objSearch.Get; Object obj; //Loop through all the processes in objCol to find the one you want. foreach(System.Management.Object objProc in objCol) { //if the obj is the proc you are after obj = objProc.InvokeMethod("GetOwner",info); //where info is an array look at docs //I think info[0] is domain and info[1] is user } This example code was cobbled together in the message reply editor, and I do not use c# enough to say that these are valid statements, but if you read the documentation on the System.Management objects used, you should be able to figure it out. Scott Serl

      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