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 / C++ / MFC
  4. GetUserName() return "SYSTEM" FOR SYSTEM PROCESS

GetUserName() return "SYSTEM" FOR SYSTEM PROCESS

Scheduled Pinned Locked Moved C / C++ / MFC
jsonquestion
5 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.
  • V Offline
    V Offline
    vicky00000
    wrote on last edited by
    #1

    For getting the user name in, we are call the GetUserName() in the Application context, in which case we get it right if the Application is launched form logged in user. But in case of system process GetUserName() return "SYSTEM" as current user. There is any API or Method to get the current user name in system process? THANKS IN ADVANCE

    M M 2 Replies Last reply
    0
    • V vicky00000

      For getting the user name in, we are call the GetUserName() in the Application context, in which case we get it right if the Application is launched form logged in user. But in case of system process GetUserName() return "SYSTEM" as current user. There is any API or Method to get the current user name in system process? THANKS IN ADVANCE

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

      Look at regestry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer value Logon User Name

      V M 2 Replies Last reply
      0
      • M myshketer

        Look at regestry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer value Logon User Name

        V Offline
        V Offline
        vicky00000
        wrote on last edited by
        #3

        the value at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer a

        1 Reply Last reply
        0
        • M myshketer

          Look at regestry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer value Logon User Name

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

          myshketer wrote:

          HKEY_CURRENT_USER

          How will that work from a service running as a different "user"? Mark

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

          1 Reply Last reply
          0
          • V vicky00000

            For getting the user name in, we are call the GetUserName() in the Application context, in which case we get it right if the Application is launched form logged in user. But in case of system process GetUserName() return "SYSTEM" as current user. There is any API or Method to get the current user name in system process? THANKS IN ADVANCE

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

            For systems with fast user switching (XP+) where more than one user can be logged on at the same time, maybe something like this:

            #include <WtsApi32.h> // link to WtsApi32.lib
            ...
            DWORD dwSessionId = WTSGetActiveConsoleSessionId();
            if (0xFFFFFFFF != dwSessionId)
            {
            LPTSTR pUserNameStr = 0;
            DWORD dwBytesReturned = 0;

            if (WTSQuerySessionInformation(WTS\_CURRENT\_SERVER\_HANDLE, dwSessionId, WTSUserName, &pUserNameStr, &dwBytesReturned))
            {
                // ... use pUserNameStr ...
            
                WTSFreeMemory(pUserNameStr);
            }
            

            }

            Mark

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

            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