Unique identifier for user profiles in Windows

你说的曾经没有我的故事 提交于 2019-12-03 09:13:23

Windows users and groups use security identifiers (SIDs).

A security identifier (SID) is a unique value of variable length that is used to identify a security principal or security group in Windows operating systems.

There is a list of predefined SIDs that Windows has built-in. Other SIDs are generated by combining the current computer's (randomly generated, 96-bit) SID with an incremented number.

SIDs of users that have accounts on a computer are stored in the registry under HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList

Sample SIDs (taken from The Microsoft policy concerning disk duplication of Windows XP installations):

The following example displays the SIDs for four local user accounts. Note that only the last four digits are incremented as new accounts are added.

  • S-1-5-21-191058668-193157475-1542849698-500 Administrator
  • S-1-5-21-191058668-193157475-1542849698-1000 User 1
  • S-1-5-21-191058668-193157475-1542849698-1001 User 2
  • S-1-5-21-191058668-193157475-1542849698-1002 User 3

Because of how SIDs are generated, they should be unique. Since they are part of the windows profile system, roaming profiles should have the same SID on every system.

You could use the user profile's security identifier (SID).

The LookupAccountName() Win32 API takes a user name and computer name as input and gives you back the associated SID.

R Bemrose and snowccrash are correct, the account SID is precisely what you have requested. You are correct that in order for this solution to work you much enable roaming profiles; that's why they're called roaming profiles.

If you don't want to use domain authentication to identify users then your other option is WAS (Windows Authentication Services). This is typically but not necessarily implemented atop Microsoft SQL Server in the ubiquitous ASPNETDB database.

WAS is a dotnet solution, with elaborate support for ASP.NET that is also available for desktop software. If you don't like that either, you can roll your own but this seems to me a suboptimal application of resources. If you aren't building dotnet software you could still exploit WAS but it won't be quite so convenient.

I might use a more LDAP-centric solution to this problem, but it might be a lot more work for your app.

There are a few unique fields in AD for user. You could use the whole DN of a User record (i.e. DC=com,DC=example,CN=Users,DN=bob smith). That's what uniquely identifies a record in AD. However, MS also has a field called UPN, which looks like an email address (sometimes it is) and takes the form user@domain.

Of course, this information requires read access to AD and that may not be practical for your app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!