Close LogonUser Handle if Failed Logon?
Question
The LogonUser function http://msdn.microsoft.com/en-us/library/aa378184(VS.85).aspx returns a handle that you can use to impersonate the user, when you are done using it you call CloseHandle to close it. My question is, do you need to close the handle if the logon attempt fails (ie wrong username or password)?
Solution
No. LogonUser
returns zero if it fails and no handle is created. Though, if you do call CloseHandle
on it, CloseHandle
should just return ERROR_INVALID_HANDLE
.
OTHER TIPS
The location pointed to by phToken
is an "out" parameter, so if LogonUser()
fails you should not count on it storing any reasonable value. You don't need to call CloseHandle() in such case.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow