My Windows application uses
In real environment, the application works fine, because nobody would add the user and delete it right away. However, my test does that, so it sporadically fails at NetUserGetInfo or NetUserDel in an unexpected way. There is no error code returned. The application just terminates silently in Windows 7 and Windows 10.
I could imagine that when NetUserAdd returns, the user account might not have been fully constructed yet in the background. Is there a recommended way to check whether a user account is in a stable state before calling NetUserDel?
LookupAccountName always succeeds, so it is not a good guard. NetUserGetInfo itself sporadically fails unexpectedly. I failed to find other API in MSDN documentation (very few examples there).
Instead of using those unstable win32 API, calling DOS command "net user" via system() can circumvent the issue.