PowerBuilder – Getting Active Directory information

Posted on Monday, September 27th, 2010 at 8:00 pm in

Here is a handy bit of OLE to retrieve Active Directory information.

oleobject ads
string ls_stuff
ads = CREATE OleObject

ads.ConnectToNewObject( "ADSystemInfo" )

ls_stuff = 'User: ' + String(ads.UserName)
ls_stuff += '~n~r' + 'Computer: ' + string(ads.ComputerName)
ls_stuff += '~n~r' + 'Domain: ' + string(ads.DomainDNSName)
ls_stuff += '~n~r' + 'Domain short: ' + string(ads.DomainShortName)
ls_stuff += '~n~r' + 'Forest: ' + string(ads.ForestDNSName)
ls_stuff += '~n~r' + 'Native Mode: ' + string(ads.IsNativeMode)
ls_stuff += '~n~r' + 'PDCRoleOwner: ' + string(ads.PDCRoleOwner)
ls_stuff += '~n~r' + 'SchemaRoleOwner: ' + string(ads.SchemaRoleOwner)
ls_stuff += '~n~r' + 'Site: ' + string(ads.SiteName)


MessageBox("Active Directory - Information",ls_stuff)
DESTROY(ads)

Sample output from the above example:

More information here:

From the Microsoft link

ADSystemInfo interface defines the following properties. All are read only

ComputerName
Retrieves the distinguished name of the local computer.

DomainDNSName
Retrieves the DNS name of the local computer domain, for example “example.fabrikam.com”.

DomainShortName
Retrieves the short name of the local computer domain, for example “myDom”.

ForestDNSName
Retrieves the DNS name of the local computer forest.

IsNativeMode
Determines whether the local computer domain is in native or mixed mode.

PDCRoleOwner
Retrieves the distinguished name of the NTDS-DSA object for the DC that owns the primary domain controller role in the local computer domain.

SchemaRoleOwner
Retrieves the distinguished name of the NTDS-DSA object for the DC that owns the schema role in the local computer forest.

SiteName
Retrieves the site name of the local computer.

UserName
Retrieves the Active Directory distinguished name of the current user, which is the logged-on user or the user impersonated by the calling thread.

Top