Get Windows user account SID by account name only

1.2k views Asked by At

I am trying to programmatically delete a user profile (the right way) using the DeleteProfile() API. Unfortunately, it wants an account SID as the first parameter.

There has to be some magical API that takes a username and spits out an SID, correct? I can't seem to find anything online that is uses native code (I am not using .NET managed code and don't want to use WMI queries or powershell or cmdline tools, etc)

I know you can use the Net32Api to delete an account, but that still leaves artifacts like profile directory, etc. I just want a way to cleanly delete a profile (obviously from elevated code).

Thank you!

1

There are 1 answers

0
Frankie_C On BEST ANSWER

You can use the buddy function LookupAccountName().

See https://msdn.microsoft.com/en-us/library/windows/desktop/aa379159(v=vs.85).aspx