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 / C++ / MFC
  4. Getting the User Name for a Process

Getting the User Name for a Process

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiocomhelp
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.
  • R Offline
    R Offline
    Rajesh_Parameswaran
    wrote on last edited by
    #1

    Hi there, I'm working on a Application developed using Visual Studio 2008 (VC++). I'm looking for a way to get the name of the current user session using the process ID. My intention here is to check for a particular process (AA.exe) and see this is not running for a current user. I'm using the CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL) to get the list of process, and traverse thru the list for a matching AA.exe process. But this returns the list of processes from all users. I've gone thru the example: List Processes Which Are Created By Specific Users[^] But the function LookupAccountSid() returns 0 and the get last error also returns 0. The value of the username field seems to be NULL. Kindly let me know, if there are any other ways to get the name of the current user session using the Process ID. Thanks in advance. regards, Rajesh

    M 1 Reply Last reply
    0
    • R Rajesh_Parameswaran

      Hi there, I'm working on a Application developed using Visual Studio 2008 (VC++). I'm looking for a way to get the name of the current user session using the process ID. My intention here is to check for a particular process (AA.exe) and see this is not running for a current user. I'm using the CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL) to get the list of process, and traverse thru the list for a matching AA.exe process. But this returns the list of processes from all users. I've gone thru the example: List Processes Which Are Created By Specific Users[^] But the function LookupAccountSid() returns 0 and the get last error also returns 0. The value of the username field seems to be NULL. Kindly let me know, if there are any other ways to get the name of the current user session using the Process ID. Thanks in advance. regards, Rajesh

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      In the call to LookupAccountSid() both cchName and cchReferencedDomainName are uninitialized. If you set them to 255 before the call does it work then?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      R 1 Reply Last reply
      0
      • M Mark Salsbery

        In the call to LookupAccountSid() both cchName and cchReferencedDomainName are uninitialized. If you set them to 255 before the call does it work then?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        R Offline
        R Offline
        Rajesh_Parameswaran
        wrote on last edited by
        #3

        Thanks Mark. It worked after initializing those two variables. regards, Rajesh

        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