home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / Perl / binding.pl next >
Encoding:
Text File  |  1998-10-06  |  2.0 KB  |  86 lines

  1. # This sample demonstrates how to bind to DS Object
  2.  
  3. use OLE;             # Include OLE and Win32 extensions
  4. use Win32;
  5.  
  6. # Create the Global Providers object
  7. $adsiNameSpaces = CreateObject OLE 'ADsNameSpaces'
  8.                   or warn "Couldn't create new instance of the ADSI Name Spaces Check your registry for ADsNameSpaces key under classes!!";
  9.  
  10. $errNum = Win32::OLELastError;
  11. if ($errNum != 0)
  12. {
  13.    print "OLE Error0: ", Win32::FormatMessage($errNum);
  14.    exit(1);
  15. }
  16. else
  17. {
  18.     print "Successfully created the NameSpaces object\n";
  19. }
  20.  
  21. # Now get the LDAP Provider object 
  22. $ldapNameSpace = $adsiNameSpaces->getobject("", "LDAP:");
  23.  
  24. $errNum = Win32::OLELastError;
  25. if ($errNum != 0)
  26. {
  27.    print "OLE Error1: ", Win32::FormatMessage($errNum);
  28.    exit(1);
  29. }
  30. else
  31. {
  32.     print "Successfully got the LDAP Provider object\n";
  33. }
  34. #######################
  35. # Let us bind to a DS #
  36. #######################
  37. $myDSObject = $ldapNameSpace->OpenDSObject("LDAP:/\/\NW01T1/\DC=NW01T1DOM,DC=NTDEV,DC=Microsoft,DC=Com", "cn=administrator,cn=users,dc=nw01t1dom,dc=ntdev,dc=microsoft,dc=com", "", 1);
  38.  
  39. $errNum = Win32::OLELastError;
  40. if ($errNum != 0)
  41. {
  42.    print "OLE Error2: ", Win32::FormatMessage($errNum);
  43.    exit(1);
  44. }
  45. else
  46. {
  47.     print "Successfully bound to an object\n";
  48. }
  49.  
  50. # Close handles to the OLE objects
  51. DestroyObject OLE $myDSObject;
  52. $errNum = Win32::OLELastError;
  53. if ($errNum != 0)
  54. {
  55.    print "OLE Error3: ", Win32::FormatMessage($errNum);
  56.    exit(1);
  57. }
  58. else
  59. {
  60.     print "Successfully destroyed the object myDSObject\n";
  61. }
  62.  
  63. DestroyObject OLE $ldapNameSpace;
  64. $errNum = Win32::OLELastError;
  65. if ($errNum != 0)
  66. {
  67.    print "OLE Error4: ", Win32::FormatMessage($errNum);
  68.    exit(1);
  69. }
  70. else
  71. {
  72.     print "Successfully destroyed the object ldapNameSpace \n";
  73. }
  74.  
  75. DestroyObject OLE $adsiNameSpaces;
  76. $errNum = Win32::OLELastError;
  77. if ($errNum != 0)
  78. {
  79.    print "OLE Error5: ", Win32::FormatMessage($errNum);
  80.    exit(1);
  81. }
  82. else
  83. {
  84.     print "Successfully destroyed the object adsiNameSpaces \n";
  85. }
  86.