get GUID for object attribute/property

get GUID for object attribute/property

Post by Carste » Tue, 26 Nov 2002 18:16:34



Hi,

the GUID of an Object or Attribute is in the
Property "schemaIDGUID".

So you must Quest for the cn in the Schema Container.
Therefor you get an IDirectorySearch Object for the Schema
Container and call the ExecuteSearch Function with the
Filter (cn=department) and the ResultAttribut LPWSTR
ResultAttributes[]={L"schemaIDGUID"}. In the first
Resultcolumn you can read out the SchemaIDGuid.

If you want to make an Node Type from the SchemaIDGUID to
extend the Schema, you can use this code:

(It based on a Win32 Console Application)

#include "stdafx.h"
#include <wchar.h>
#include <activeds.h>

HRESULT GetCOMGUIDStr(LPOLESTR
*ppAttributeName,IDirectoryObject *pDO, LPOLESTR
*ppGUIDString)
{
    HRESULT hr = S_OK;
    PADS_ATTR_INFO  pAttribu*tries;
    VARIANT varX;
    DWORD dwAttributesReturned = 0;
    hr = pDO->GetObjectAttributes
              (
                 ppAttributeName, // objectGUID
                 1, // Only objectGUID
                 &pAttribu*tries, // Returned attributes
                 &dwAttributesReturned //Number of
attributes returned
              );
    if (SUCCEEDED(hr) && dwAttributesReturned>0)
    {
        // This step ensures that the correct type is used
        if (ADSTYPE_OCTET_STRING == pAttribu*tries-

Quote:>dwADsType)

        {
            LPGUID pObjectGUID = (GUID*)(pAttribu*tries-
                                 pADsValues
[0].OctetString.lpValue);
            //OLE str to fit a GUID
            LPOLESTR szDSGUID = new WCHAR [39];
            //Convert GUID to string.
            ::StringFromGUID2(*pObjectGUID, szDSGUID, 39);
            *ppGUIDString = (OLECHAR *)CoTaskMemAlloc
                            (sizeof(OLECHAR)*(wcslen
(szDSGUID)+1));

            if (*ppGUIDString)
               wcscpy(*ppGUIDString, szDSGUID);
            else
                hr = E_FAIL;
        }

        else
            hr = E_FAIL;

    //Free the memory for the attributes.
    FreeADsMem(pAttribu*tries);
    VariantClear(&varX);
    }
    return hr;

Quote:}

int main(int argc, char* argv[])
{
        LPOLESTR szPath = new OLECHAR[MAX_PATH];
    HRESULT hr = S_OK;
    IADs *pObject = NULL;
    VARIANT var;
    IDirectoryObject *pDO = NULL;
    LPOLESTR pAttributeName = L"schemaIDGUID";
    LPOLESTR pGUIDString = NULL;

    wcscpy(szPath, L"LDAP://");
    CoInitialize(NULL);
    //Get rootDSE and the schema container's DN.
    //Bind to current user's domain using current user's
    //security context.
    hr = ADsOpenObject(L"LDAP://rootDSE",
                NULL,
                NULL,
                ADS_SECURE_AUTHENTICATION, //Use Secure
Authentication
                IID_IADs,
                (void**)&pObject);

    if (SUCCEEDED(hr))
    {
        hr = pObject->Get(L"schemaNamingContext",&var);
        if (SUCCEEDED(hr))
        {
            wcscat(szPath, L"cn=ncpMprWANLink,");
            wcscat(szPath, var.bstrVal);
            hr = ADsOpenObject(szPath,
                    NULL,
                    NULL,
                    ADS_SECURE_AUTHENTICATION, //Use
Secure
                                               //Authentica
tion
                    IID_IDirectoryObject,
                    (void**)&pDO);
            if (SUCCEEDED(hr))
            {
                hr = GetCOMGUIDStr(&pAttributeName,
                            pDO,
                            &pGUIDString);
                if (SUCCEEDED(hr))
                                        wprintf
(pGUIDString);
                        }
                }
        }
        if (pDO)
        pDO->Release();
    VariantClear(&var);
        CoUninitialize();
        return 0;

Quote:}

I hope it helps you.
Quote:>-----Original Message-----
>Hi,

>how can i get the GUID for object attribute/property.
>Example: GUID for department(attribute for user object)

>Thanks in advanced
>.

 
 
 

get GUID for object attribute/property

Post by krayo » Tue, 26 Nov 2002 20:15:01


Thanks.
err..if you don't mind..do you have the vb sample.

tq.
Krayon

Quote:>-----Original Message-----
>Hi,

>the GUID of an Object or Attribute is in the
>Property "schemaIDGUID".

>So you must Quest for the cn in the Schema Container.
>Therefor you get an IDirectorySearch Object for the
Schema
>Container and call the ExecuteSearch Function with the
>Filter (cn=department) and the ResultAttribut LPWSTR
>ResultAttributes[]={L"schemaIDGUID"}. In the first
>Resultcolumn you can read out the SchemaIDGuid.

>If you want to make an Node Type from the SchemaIDGUID
to
>extend the Schema, you can use this code:

>(It based on a Win32 Console Application)

>#include "stdafx.h"
>#include <wchar.h>
>#include <activeds.h>

>HRESULT GetCOMGUIDStr(LPOLESTR
>*ppAttributeName,IDirectoryObject *pDO, LPOLESTR
>*ppGUIDString)
>{
>    HRESULT hr = S_OK;
>    PADS_ATTR_INFO  pAttribu*tries;
>    VARIANT varX;
>    DWORD dwAttributesReturned = 0;
>    hr = pDO->GetObjectAttributes
>              (
>                 ppAttributeName, // objectGUID
>                 1, // Only objectGUID
>                 &pAttribu*tries, // Returned
attributes
>                 &dwAttributesReturned //Number of
>attributes returned
>              );
>    if (SUCCEEDED(hr) && dwAttributesReturned>0)
>    {
>        // This step ensures that the correct type is
used
>        if (ADSTYPE_OCTET_STRING == pAttribu*tries-
>>dwADsType)
>        {
>            LPGUID pObjectGUID = (GUID*)
(pAttribu*tries-

>                                 pADsValues
>[0].OctetString.lpValue);
>            //OLE str to fit a GUID
>            LPOLESTR szDSGUID = new WCHAR [39];
>            //Convert GUID to string.
>            ::StringFromGUID2(*pObjectGUID, szDSGUID,
39);
>            *ppGUIDString = (OLECHAR *)CoTaskMemAlloc
>                            (sizeof(OLECHAR)*(wcslen
>(szDSGUID)+1));

>            if (*ppGUIDString)
>               wcscpy(*ppGUIDString, szDSGUID);
>            else
>                hr = E_FAIL;
>        }

>        else
>            hr = E_FAIL;

>    //Free the memory for the attributes.
>    FreeADsMem(pAttribu*tries);
>    VariantClear(&varX);
>    }
>    return hr;
>}

>int main(int argc, char* argv[])
>{
>    LPOLESTR szPath = new OLECHAR[MAX_PATH];
>    HRESULT hr = S_OK;
>    IADs *pObject = NULL;
>    VARIANT var;
>    IDirectoryObject *pDO = NULL;
>    LPOLESTR pAttributeName = L"schemaIDGUID";
>    LPOLESTR pGUIDString = NULL;

>    wcscpy(szPath, L"LDAP://");
>    CoInitialize(NULL);
>    //Get rootDSE and the schema container's DN.
>    //Bind to current user's domain using current user's
>    //security context.
>    hr = ADsOpenObject(L"LDAP://rootDSE",
>                NULL,
>                NULL,
>                ADS_SECURE_AUTHENTICATION, //Use Secure
>Authentication
>                IID_IADs,
>                (void**)&pObject);

>    if (SUCCEEDED(hr))
>    {
>        hr = pObject->Get(L"schemaNamingContext",&var);
>        if (SUCCEEDED(hr))
>        {
>            wcscat(szPath, L"cn=ncpMprWANLink,");
>            wcscat(szPath, var.bstrVal);
>            hr = ADsOpenObject(szPath,
>                    NULL,
>                    NULL,
>                    ADS_SECURE_AUTHENTICATION, //Use
>Secure
>                                               //Authenti
ca
>tion
>                    IID_IDirectoryObject,
>                    (void**)&pDO);
>            if (SUCCEEDED(hr))
>            {
>                hr = GetCOMGUIDStr(&pAttributeName,
>                            pDO,
>                            &pGUIDString);
>                if (SUCCEEDED(hr))
>                                    wprintf
>(pGUIDString);
>                    }
>            }
>    }
>    if (pDO)
>        pDO->Release();
>    VariantClear(&var);
>    CoUninitialize();
>    return 0;
>}

>I hope it helps you.
>>-----Original Message-----
>>Hi,

>>how can i get the GUID for object attribute/property.
>>Example: GUID for department(attribute for user object)

>>Thanks in advanced
>>.

>.


 
 
 

get GUID for object attribute/property

Post by Carste » Tue, 26 Nov 2002 22:28:35


No, sorry, but the code is from:

http://www.veryComputer.com/
url=/library/en-us/mmc/mmc/registering_node_type.asp

Could be, that you find something in the same Direction
for vb in the Area arround this Article.

Quote:>-----Original Message-----
>Thanks.
>err..if you don't mind..do you have the vb sample.

>tq.
>Krayon

>>-----Original Message-----
>>Hi,

>>the GUID of an Object or Attribute is in the
>>Property "schemaIDGUID".

>>So you must Quest for the cn in the Schema Container.
>>Therefor you get an IDirectorySearch Object for the
>Schema
>>Container and call the ExecuteSearch Function with the
>>Filter (cn=department) and the ResultAttribut LPWSTR
>>ResultAttributes[]={L"schemaIDGUID"}. In the first
>>Resultcolumn you can read out the SchemaIDGuid.

>>If you want to make an Node Type from the SchemaIDGUID
>to
>>extend the Schema, you can use this code:

>>(It based on a Win32 Console Application)

>>#include "stdafx.h"
>>#include <wchar.h>
>>#include <activeds.h>

>>HRESULT GetCOMGUIDStr(LPOLESTR
>>*ppAttributeName,IDirectoryObject *pDO, LPOLESTR
>>*ppGUIDString)
>>{
>>    HRESULT hr = S_OK;
>>    PADS_ATTR_INFO  pAttribu*tries;
>>    VARIANT varX;
>>    DWORD dwAttributesReturned = 0;
>>    hr = pDO->GetObjectAttributes
>>              (
>>                 ppAttributeName, // objectGUID
>>                 1, // Only objectGUID
>>                 &pAttribu*tries, // Returned
>attributes
>>                 &dwAttributesReturned //Number of
>>attributes returned
>>              );
>>    if (SUCCEEDED(hr) && dwAttributesReturned>0)
>>    {
>>        // This step ensures that the correct type is
>used
>>        if (ADSTYPE_OCTET_STRING == pAttribu*tries-
>>>dwADsType)
>>        {
>>            LPGUID pObjectGUID = (GUID*)
>(pAttribu*tries-

>>                                 pADsValues
>>[0].OctetString.lpValue);
>>            //OLE str to fit a GUID
>>            LPOLESTR szDSGUID = new WCHAR [39];
>>            //Convert GUID to string.
>>            ::StringFromGUID2(*pObjectGUID, szDSGUID,
>39);
>>            *ppGUIDString = (OLECHAR *)CoTaskMemAlloc
>>                            (sizeof(OLECHAR)*(wcslen
>>(szDSGUID)+1));

>>            if (*ppGUIDString)
>>               wcscpy(*ppGUIDString, szDSGUID);
>>            else
>>                hr = E_FAIL;
>>        }

>>        else
>>            hr = E_FAIL;

>>    //Free the memory for the attributes.
>>    FreeADsMem(pAttribu*tries);
>>    VariantClear(&varX);
>>    }
>>    return hr;
>>}

>>int main(int argc, char* argv[])
>>{
>>        LPOLESTR szPath = new OLECHAR[MAX_PATH];
>>    HRESULT hr = S_OK;
>>    IADs *pObject = NULL;
>>    VARIANT var;
>>    IDirectoryObject *pDO = NULL;
>>    LPOLESTR pAttributeName = L"schemaIDGUID";
>>    LPOLESTR pGUIDString = NULL;

>>    wcscpy(szPath, L"LDAP://");
>>    CoInitialize(NULL);
>>    //Get rootDSE and the schema container's DN.
>>    //Bind to current user's domain using current user's
>>    //security context.
>>    hr = ADsOpenObject(L"LDAP://rootDSE",
>>                NULL,
>>                NULL,
>>                ADS_SECURE_AUTHENTICATION, //Use Secure
>>Authentication
>>                IID_IADs,
>>                (void**)&pObject);

>>    if (SUCCEEDED(hr))
>>    {
>>        hr = pObject->Get(L"schemaNamingContext",&var);
>>        if (SUCCEEDED(hr))
>>        {
>>            wcscat(szPath, L"cn=ncpMprWANLink,");
>>            wcscat(szPath, var.bstrVal);
>>            hr = ADsOpenObject(szPath,
>>                    NULL,
>>                    NULL,
>>                    ADS_SECURE_AUTHENTICATION, //Use
>>Secure
>>                                               //Authenti
>ca
>>tion
>>                    IID_IDirectoryObject,
>>                    (void**)&pDO);
>>            if (SUCCEEDED(hr))
>>            {
>>                hr = GetCOMGUIDStr(&pAttributeName,
>>                            pDO,
>>                            &pGUIDString);
>>                if (SUCCEEDED(hr))
>>                                        wprintf
>>(pGUIDString);
>>                        }
>>                }
>>        }
>>        if (pDO)
>>        pDO->Release();
>>    VariantClear(&var);
>>        CoUninitialize();
>>        return 0;
>>}

>>I hope it helps you.
>>>-----Original Message-----
>>>Hi,

>>>how can i get the GUID for object attribute/property.
>>>Example: GUID for department(attribute for user object)

>>>Thanks in advanced
>>>.

>>.

>.

 
 
 

1. Getting object via GUID

Hello,

  I have been serching through the newsgroup posting in
adsi.general and see a lot of posting regarding binding to
an object with it's guid.  I am trying to bind to the
object specified by the ObjectType in a
IADsAccessControlEntry.  I am able to retrieve the object
when it is a controlAccessRight, but not when it refers to
an object.  I have tried converting the string guid to an
octet value using some code I found in the newsgroup, but
I keep getting the message back that there is no such
object on the server.  Has anyone had any success doing
this?

Thanks,

Tony

2. Screen freeze with cd-rom drive

3. Urgent: Getting AD objects by GUID in .NET

4. <<<PLAYSTATION COPY on MAC?>>>

5. Adding properties (attributes) to existing objects... help!

6. SMTP Outbound Authentication

7. Help With User Object - Getting Attributes

8. HELP: Getting strange disk errors with .EXE files on floppy

9. getting attributes of computer object

10. ways to access properties using ADSI IADsUser object properties like telephoneno

11. How To:Get user attribute guid

12. Identical GUID for every object