GetUserName() API failing condition
-
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?
-
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?
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++]
-
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++]
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.
-
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.
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++]
-
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.
It fails when computer username is set as UnknownUser ;P
-
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?
Whats your operating system?