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() API failing condition

GetUserName() API failing condition

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

    When will GetUserName() Win32 API fail,other than inadequate buffer size? The application is run by a service at startup,and occasionally the GetUserName() fails (returns false). However most of the times it gives the correct user name. Can any shed some light on this?

    R H 2 Replies Last reply
    0
    • K ktm TechMan

      When will GetUserName() Win32 API fail,other than inadequate buffer size? The application is run by a service at startup,and occasionally the GetUserName() fails (returns false). However most of the times it gives the correct user name. Can any shed some light on this?

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      You can call GetLastError()[^] in case of a failure to find out what went wrong.

      Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

      K 1 Reply Last reply
      0
      • R Rajesh R Subramanian

        You can call GetLastError()[^] in case of a failure to find out what went wrong.

        Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

        K Offline
        K Offline
        ktm TechMan
        wrote on last edited by
        #3

        I did that, but its really very hard to replicate it. I was asking for any particular scenario that might have caused the function to fail. Any peculiar experiences regarding the function use? Anyways Thanks.

        R T 2 Replies Last reply
        0
        • K ktm TechMan

          I did that, but its really very hard to replicate it. I was asking for any particular scenario that might have caused the function to fail. Any peculiar experiences regarding the function use? Anyways Thanks.

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          No, I don't have any peculiar experience with the function. But I suggest that you log all the failures (with reasons) and that would be a good way to analyse what goes crazy. :)

          Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

          1 Reply Last reply
          0
          • K ktm TechMan

            I did that, but its really very hard to replicate it. I was asking for any particular scenario that might have caused the function to fail. Any peculiar experiences regarding the function use? Anyways Thanks.

            T Offline
            T Offline
            TheRealEye
            wrote on last edited by
            #5

            It fails when computer username is set as UnknownUser ;P

            1 Reply Last reply
            0
            • K ktm TechMan

              When will GetUserName() Win32 API fail,other than inadequate buffer size? The application is run by a service at startup,and occasionally the GetUserName() fails (returns false). However most of the times it gives the correct user name. Can any shed some light on this?

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Whats your operating system?

              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