How to use windows authentication (local machine administrator user) in windows application written in C#.
Need is whenever user opens my windows application GUI, it should authenticate local administrator credentials even if User is logged in as Administrator there.
Is this windows Impersonation?
You can call the
LogonUserAPI method to check a username and password.You can see the
[DllImport]here.If you want to show a standard username/password prompt, you can call the CredUIPromptForCredentials API function; see also here
EDIT
To check whether the user is an administrator, you can call
CheckTokenMembershipand check whether the user is in theAdministratorsgroup.Alternatively, you can call
NetUserGetInfolevel 1 and check whetherusri1_privisUSER_PRIV_ADMIN.You can also use WMI or DirectoryServices.