Guest User

Untitled

a guest
Aug 7th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System;
  2. using System.DirectoryServices;
  3.  
  4. namespace BrunoMartinsPro.TriggerErrors
  5. {
  6. public class AdErrorUtils
  7. {
  8. public void TriggerError()
  9. {
  10. //Define connection properties
  11. string ADConnectionString = "LDAP://AD.brunomartins.pro";
  12. string ADUserLogin = "BrunoMartinsPro";
  13. string ADUserPassword = "WoWWoWBadCommunication";
  14.  
  15. //Create entry
  16. DirectoryEntry entry = new DirectoryEntry(ADConnectionString, ADUserLogin, ADUserPassword);
  17.  
  18. //Create searcher
  19. DirectorySearcher searcher = new DirectorySearcher(entry);
  20.  
  21. //Define filter
  22. searcher.Filter = "(SAMAccountname=" + "BrunoMartinsPro" + ")";
  23.  
  24. //Load ad properties
  25. searcher.PropertiesToLoad.Add("name");
  26. searcher.PropertiesToLoad.Add(null);
  27.  
  28. //Associate Directory Entry
  29. searcher.SearchRoot = entry;
  30.  
  31. //Execute search
  32. SearchResult adUser = searcher.FindOne();
  33.  
  34. //Execute search throws an exception:
  35. //'System.AccessViolationException' in System.DirectoryServices.dll
  36. //Attempted to read or write protected memory.This is often an indication that other memory is corrupt.
  37. //This happens because no property NULL exists
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment