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. Get default user name when "Run as administrator"

Get default user name when "Run as administrator"

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
6 Posts 4 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.
  • S Offline
    S Offline
    sireesha_sree
    wrote on last edited by
    #1

    Hi, Am developing a VC++ application where i need to get the username. I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in. Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"? Thanks

    _ _ D 3 Replies Last reply
    0
    • S sireesha_sree

      Hi, Am developing a VC++ application where i need to get the username. I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in. Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"? Thanks

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You could try GetEnvironmentStrings. Then look for USERNAME variable.

      «_Superman_» I love work. It gives me something to do between weekends.
      Microsoft MVP (Visual C++)

      S 1 Reply Last reply
      0
      • _ _Superman_

        You could try GetEnvironmentStrings. Then look for USERNAME variable.

        «_Superman_» I love work. It gives me something to do between weekends.
        Microsoft MVP (Visual C++)

        S Offline
        S Offline
        sireesha_sree
        wrote on last edited by
        #3

        Thanks for the reply. I have already tried that. It is returning the administrators username when i run the app as "Run as administrator". But i want the system logged on user name.

        _ 1 Reply Last reply
        0
        • S sireesha_sree

          Hi, Am developing a VC++ application where i need to get the username. I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in. Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"? Thanks

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          Did you see here[^]

          You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

          1 Reply Last reply
          0
          • S sireesha_sree

            Hi, Am developing a VC++ application where i need to get the username. I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in. Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"? Thanks

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Have you looked at LsaEnumerateLogonSessions()?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Man who follows car will be exhausted." - Confucius

            1 Reply Last reply
            0
            • S sireesha_sree

              Thanks for the reply. I have already tried that. It is returning the administrators username when i run the app as "Run as administrator". But i want the system logged on user name.

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              The reason why I gave you the answer is this - I run a normal command prompt and run the set command which lists the environment variables. Here it lists USERNAME=xxx. I then run the command prompt as administrator and then do the same thing. The USERNAME variable lists the same user.

              «_Superman_» I love work. It gives me something to do between weekends.
              Microsoft MVP (Visual C++)

              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