Question
I did not know that it would be difficult to understand, but I am here.
I am developing a network support client that should determine if the current user in the system has a password. I tried it with WMI, checking the PasswordRequired property in the Win32_UserAccount class, but it returns false even if my account is password protected . I have no ideas ...
(Background: I need this information to tell the user that he needs to install it so that I can connect to it through the remote desktop, which is not very happy if the account is โinsecure.โ If there is a way to get around this, I also accept another solution.)
Yours sincerely
Nefarius
Decision
Easier than I thought, I was able to use the WinAPI LogonUser function and provide you with this simple shell code:
private bool PasswordRequired { get { 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; } }
This is exactly what I need, thank you all for your prompt and competent answers, I can always count on you! =)
Nefarius
source share