Platform SDK: Active Directory, ADSI, and Directory Services

IADsPathname Property Methods

The property methods of the IADsPathname interface get or set the properties described in the following table. For more information, see Interface Property Methods.

Properties in Vtable Order

Property Description
EscapedMode

[Visual Basic]
Access: Read/Write
Data type: LONG

[C++]
HRESULT get_EscapedMode
([retval][out] LONG *retval);

Examine or specify how escaped characters are handled in a pathname. The options are defined in ADS_ESCAPE_MODE_ENUM.

Remarks

EscapedMode represents a state. You can turn it on or off, by setting it to ADS_ESCAPEDMODE_ON or ADS_ESCAPEDMODE_OFF/ADS_ESCAPEDMODE_OFF_EX, at any time. Once it is turned on (or off), all subsequent retrievals produce escaped or unescaped path strings.

In ADSI only the IADsPathname is capable of unescaping paths. All other ADSI interfaces always return escaped ones. The default state of EscapedMode is ADS_ESCAPEDMODE_DEFAULT as defined in ADS_ESCAPE_MODE_ENUM.

Example Code [Visual Basic]

The following Visual Basic® code snippet shows how to use the EscapedMode property turn on/off escaping of the following three special characters: "=",",", and "/".

Dim path As New Pathname
path.Set "CN=foo\=bar\,\/*", ADS_SETTYPE_DN
 
path.EscapedMode = ADS_ESCAPEDMODE_ON
MsgBox path.Retrieve(ADS_FORMAT_WINDOWS)  ' all escaped, producing
                                          ' "LDAP://CN=foo\=bar\,\/*"
 
path.EscapedMode = ADS_ESCAPEMODE_OFF
MsgBox path.Retrieve(ADS_FORMAT_WINDOWS)  ' only "/" is unescaped:
                                          ' "LDAP://CN=foo\=bar\,/*"
 
path.EscapedMode = ADS_ESCAPEDMODE_OFF_EX
MsgBox path.Retrieve(ADS_FORMAT_WINDOWS)  ' all are unescaped:
                                          ' "LDAP://CN=foo=bar,/*"
 
 
path.Set "LDAP://CN=foo\=bar\,\/*", ADS_SETTYPE_FULL
 
path.EscapedMode = ADS_ESCAPEDMODE_ON
MsgBox path.Retrieve(ADS_FORMAT_WINDOWS)
                                  ' produces "LDAP://CN=foo\=bar\,\/*"
 
path.EscapedMode = ADS_ESCAPEMODE_OFF
MsgBox path.Retrieve(ADS_FORMAT_WINDOWS)
                                  ' produces "LDAP://CN=foo\=bar\,/*"
 
path.EscapedMode = ADS_ESCAPEMODE_OFF_EX
MsgBox path.Retrieve(ADS_FORMAT_WINDOWS)
                                  ' produces "LDAP://CN=foo=bar,/*"

Example Code [VBScript]

The following VBScript/ASP code snippet shows how to use the EscapedMode property turn on/off escaping of the following three special characters: "=",",", and "/".

<%
Dim path
const ADS_SETTYPE_FULL = 1
const ADS_SETTYPE_DN   = 4
const ADS_FORMAT_WINDOWS = 1
const ADS_ESCAPEDMODE_ON = 2
const ADS_ESCAPEDMODE_OFF = 3
const ADS_ESCAPEDMODE_OFF_EX = 4
 
Set path = CreateObject("Pathname")
path.Set "CN=foo\=bar\,\/*", ADS_SETTYPE_DN
 
path.EscapedMode = ADS_ESCAPEDMODE_ON
Response.Write path.Retrieve(ADS_FORMAT_WINDOWS)  ' all escaped, producing
                                          ' "LDAP://CN=foo\=bar\,\/*"
 
path.EscapedMode = ADS_ESCAPEMODE_OFF
Response.Write path.Retrieve(ADS_FORMAT_WINDOWS)  ' only "/" is unescaped:
                                          ' "LDAP://CN=foo\=bar\,/*"
 
path.EscapedMode = ADS_ESCAPEDMODE_OFF_EX
Response.Write path.Retrieve(ADS_FORMAT_WINDOWS)  ' all are unescaped:
                                          ' "LDAP://CN=foo=bar,/*"
 
 
path.Set "LDAP://CN=foo\=bar\,\/*", ADS_SETTYPE_FULL
 
path.EscapedMode = ADS_ESCAPEDMODE_ON
Response.Write path.Retrieve(ADS_FORMAT_WINDOWS)
                                  ' produces "LDAP://CN=foo\=bar\,\/*"
 
path.EscapedMode = ADS_ESCAPEMODE_OFF
Response.Write path.Retrieve(ADS_FORMAT_WINDOWS)
                                  ' produces "LDAP://CN=foo\=bar\,/*"
 
path.EscapedMode = ADS_ESCAPEMODE_OFF_EX
Response.Write path.Retrieve(ADS_FORMAT_WINDOWS)
                                  ' produces "LDAP://CN=foo=bar,/*"
%>

Example Code [C++]

The following C++ code snippet shows how to work with the EscapedMode property. For brevity, error checking is ignored.

   IADsPathname *pPathname=NULL;
   HRESULT hr;
 
   hr = CoCreateInstance(CLSID_Pathname,
                         NULL,
                         CLSCTX_INPROC_SERVER,
                         IID_IADsPathname,
                         (void**)&pPathname);
 
   if(FAILED(hr)) {
       if(pPathname) pPathname->Release();
       return NULL;
   }
 
   pPathname->AddRef();
   hr = pPathname->Set(L"LDAP://CN=foo/bar\/*",ADS_SETTYPE_FULL); 
 
   hr = pPathname->put_EscapedMode(ADS_ESCAPEDMODE_OFF);
   hr = pPathname->Retrieve(ADS_FORMAT_DN,&bstr);
   printf("Unescaped path: %S\n",bstr);   
                                // producing "LDAP://CN=foo/bar/*"
   SysFreeString(bstr);
 
   hr = pPathname->put_EscapedMode(ADS_ESCAPEDMODE_ON);
   hr = pPathname->Retrieve(ADS_FORMAT_DN,&bstr);
   printf("Escaped path: %S\n",bstr);
                               // producing "LDAP://CN=foo/bar\/*"
   SysFreeString(bstr);
 
// ////////////
//   setting the path using ADS_SETTYPE_DN
 
   hr = pPathname->Set(L"CN=foo/bar\/*",ADS_SETTYPE_DN); 
 
   hr = pPathname->put_EscapedMode(ADS_ESCAPEDMODE_OFF);
   hr = pPathname->Retrieve(ADS_FORMAT_DN,&bstr);
   printf("Unescaped path: %S\n",bstr);   
                                // producing "LDAP://CN=foo/bar/*"
   SysFreeString(bstr);
 
   hr = pPathname->put_EscapedMode(ADS_ESCAPEDMODE_ON);
   hr = pPathname->Retrieve(ADS_FORMAT_DN,&bstr);
   printf("Escaped path: %S\n",bstr);
                               // producing "LDAP://CN=foo\/bar\/*"
   SysFreeString(bstr);
 
   hr = pPathname->Release();

See Also

IADsPathname, ADS_ESCAPE_MODE_ENUM