>>>>Hello,
>>>>
>>>>Does anyone know what information VFP 9 can query from the Windows environment with regards to the user logged into the PC (I assume they log using their AD credentials). For example,
>>>>SYS(0) - User Name
>>>>Are there other SYS settings in VFP 9 that can get the user email and/or ID? Other information?
>>>>
>>>>TIA
>>>
>>>This is a method in my domainuserinfo class, GetDomainuserInfo(). it returns an object ADUser which is a class with the necessary properties that you want to use.
>>>
>>>
>>>LPARAMETERS tcUserName, tcUserDomain
>>>*
>>>#DEFINE ADS_NAME_INITTYPE_GC 3
>>>#DEFINE ADS_NAME_TYPE_NT4 3
>>>#DEFINE ADS_NAME_TYPE_1779 1
>>>*
>>>LOCAL lcCurrentUserName, lcCurrentUserDomain
>>>lcCurrentUserName = GETENV("UserName")
>>>lcCurrentUserDomain = GETENV("UserDomain")
>>>*
>>>*-- If parameters are not supplied, use current user login info
>>>LOCAL lcUserName, lcUserDomain
>>>lcUserName = EVL(tcUserName, lcCurrentUserName)
>>>lcUserDomain = EVL(tcUserDomain, lcCurrentUserDomain)
>>>*
>>>LOCAL loNameTrans, lcDN
>>>LOCAL loActiveDomainUser
>>>*
>>>LOCAL loADUser AS Aduser OF security_activedirectory.vcx
>>>loADUser = MakeObject("Aduser","security_activedirectory.vcx")
>>>*
>>>TRY
>>>
>>> *-- Use NameTranslate object to get DN based on Windows Login Name
>>> loNameTrans = CREATEOBJECT("NameTranslate")
>>> loNameTrans.Init( ADS_NAME_INITTYPE_GC, "")
>>> loNameTrans.Set(ADS_NAME_TYPE_NT4, lcUserDomain + "\" + lcUserName)
>>> lcDN = loNameTrans.Get(ADS_NAME_TYPE_1779)
>>> loActiveDomainUser = GETOBJECT("LDAP://" + lcDN)
>>> loADUser.Exists = .T.
>>> loADUser.DomainName = lcDN
>>> loADUser.FullName = loActiveDomainUser.cn
>>> loADUser.Department = loActiveDomainUser.Department
>>> loADUser.PrincipalName = loActiveDomainUser.UserPrincipalName
>>> loADUser.DistinguishedName = loActiveDomainUser.DistinguishedName
>>> loADUser.CurrentUserDomain = lcUserDomain
>>>CATCH TO oExp WHEN oExp.Errorno = 1426
>>> loActiveDomainUser = Null
>>> loADUser.Exists = .F.
>>>ENDTRY
>>>*
>>>RETURN loADUser
>>>
>>
>>Thank you very much for the sample code. Although I can see that since I don't have the "security_activedirectory.vcx", I will have to create it, somehow.
>>Another question, very newbie. Since the GETENV("UserName") gives you (if I understand correctly) the AD user name of the current user, what is the purpose of getting the loActiveDomainUser?
>
>That is because if you are not in the domain, you also get a username. So the process gets the username, and by getting the domain user I verify if we are at all connected to the AD. Also I query the other properties that are helpful.
>
>One thing I had problems with at one time was that there can be more than one domain. Not sure how that was setup, but they had a separate for Exchange I believe.
Again, thank you for your reply. And another newbie question (since I am trying to see how I can make my code work without the activedirectory class.
So, if - by convention (that is, if the customer assures) all users are on domain and connected to the AD, then I can relay on the GETENV("UserName") to give the VFP app the AD username, correct?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham