c# - How to check if windows user has a password set? -
question
i didn't know difficult figure out here am.
i'm developing net support client has detect if current logged in user has password set. tried wmi checking passwordrequired property in win32_useraccount class, returns false if account is password protected. i'm out of ideas...
(background: need info tell user has set 1 can connect him via remote desktop, isn't happy if account "unprotected". if there way around i'd accept different solution.)
sincerely yours
nefarius
solution
easier thought, managed winapi function logonuser , provide simple wrapper code:
private bool passwordrequired { { intptr phtoken; // http://www.pinvoke.net/default.aspx/advapi32/logonuser.html bool loggedin = logonuser(environment.username, null, "", (int)logontype.logon32_logon_interactive, (int)logonprovider.logon32_provider_default, out phtoken); int error = marshal.getlastwin32error(); if (phtoken != intptr.zero) // http://www.pinvoke.net/default.aspx/kernel32/closehandle.html closehandle(phtoken); // 1327 = empty password if (loggedin || error == 1327) return false; else return true; } } that's needed, thank fast , competent answers, can count on you! =)
why not try logonuser empty password?
Comments
Post a Comment