Verify your Windows account username and password

I have an installation package that installs the creation process that I create. I would like to invite the user to enter the username / password of the account with which the service process should work. I want to verify that the username and password combination is correct before proceeding with the installation. I have a C DLL that I use for special installation behavior, but I cannot figure out how to use the Windows API to verify account credentials. I would like to be able to maintain the same account name syntax that is used by the service control manager.

+7
winapi
source share
3 answers

The function you want to use is LogonUser . You can even be extra-cool and specify the LOGON32_LOGON_SERVICE flag, which checks if the user has access rights to the service.

+12
source share

LogonUser is a canonical way to do this, although Microsoft is somewhat discouraged by it .

+2
source share

I implemented this using the LogonUser function, as you guys mentioned (by the way, this service requires WinXP SP2 or later, so I'm not worried about the privilege issue). However, this is not quite as I hoped. If I call QueryServiceConfig, lpServiceStartName is in the format ". \ Accountname". If I pass this line, as in LogonUser, it fails. I assume the part before the "\" represents the machine on which the user belongs?

Also, if I call ChangeServiceConfig with "LocalSystem" and "" for the lpServiceStartName and lpPassword parameters respectively, this works fine. However, calling LogonUser does not work with these parameters.

I would really like to use the same syntax that SCM uses for account names.

0
source share

All Articles