How can my program detect whether it's running on a particular domain?

前端 未结 3 740
一整个雨季
一整个雨季 2021-01-05 22:21

I have the need to restrict specific functions of an application based on the location of the currently logged in user. As I have to implement this logic in Delphi, I\'d pre

相关标签:
3条回答
  • 2021-01-05 22:42

    I have the need to restrict specific functions of an application based on the location of the currently logged in user

    If you are trying to find out the location of the currently logged in user, you shouldn't be using DsGetDcName.

    Your computer can be joined to domainA. Your logon user can be from domainB. Calling DsGetDcName on your computer doesn't give you domainB GUID but it will give you domainA GUID

    Therefore, I think you should use LookupAccountName instead. The LookupAccountName gives you the currently logged in user's SID. Then, you can extract the domain SID from the user SID. That domain SID is really the domain where this user coming from. For the details of how to extract a domain SID from a user SID, please check here

    Regarding to your original question about the uniqueness of the domain GUID, I am sorry that I don't have answer on it. AFAIK, there is no tool available allowing you to change the domain SID nor the GUID. I am not sure how hard to hack into it and change it.

    0 讨论(0)
  • Create a service account on the domain;

    Get the GUID of the service account and encrypt it and save it somewhere (registry) maybe as part of enterprise install process to validate a license agreement.

    On startup of the client app query for the Domain Service Account GUID and validate it with the saved GUID.

    Or create your own enterprise 'key' server.

    Doing an LDAP query is easier than doing all the domain controller crap.

    0 讨论(0)
  • 2021-01-05 22:58

    If I correct understand your requirement the best API in your case is GetUserNameEx. You can choose the value of NameFormat parameter of the type EXTENDED_NAME_FORMAT which you can better verify. Another function GetComputerNameEx is helpful if you want additionally verify the information about the computer where the program is running.

    0 讨论(0)
提交回复
热议问题