I’m creating a windows service that will let different users connect to the PC over RDP.
What I need is to know how can I add, change and remove the login credentials (ie. Login + Pass) on the PC by some sort of WinAPI or by modifying regkeys or similar.
Thanks!
You can create local accounts using
NetUserAdd. You probably shouldn’t delete accounts this way, because that would orphan the user profile, but you can useNetUserGetInfoandNetUserSetInfo(option 1008) to disable and re-enable as necessary.NetUserSetInfo(option 1003) can be used to reset the password if necessary, but be aware that resetting the password causes all encrypted files and settings to be irrevocably lost. If you know the old password, you can useNetUserChangePasswordinstead.Use
NetGroupAddUserandNetGroupDelUserto add and remove accounts from the Remote Desktop Users group in order to control RDP access.Keep in mind that the accounts you create can also be used to logon interactively (unless you explicitly block this by manipulating user rights policy) and that you (presumably) will need to take care to avoid modifying the existing accounts.