Guest User

Untitled

a guest
Mar 4th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.DirectoryServices;
  5. using System.IO;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             if (args.Length != 0)
  14.             {
  15.                 try
  16.                 {
  17.                     DirectoryEntry entry = new DirectoryEntry("GC://mydomain.dk");
  18.                     entry.Username = "administrator";
  19.                     entry.Password = "mypassword";
  20.                     DirectorySearcher mySearcher = new DirectorySearcher(entry);
  21.                     mySearcher.Filter = "(sAMAccountName= " + args[0] + ")";
  22.                     foreach (SearchResult result in mySearcher.FindAll())
  23.                     {
  24.                         if (!File.Exists("user.txt"))
  25.                         {
  26.                             using (var sw = new StreamWriter("user.txt"))
  27.                             {
  28.                             sw.WriteLine(result.GetDirectoryEntry().Path);
  29.                             sw.Close();
  30.                             }
  31.                         }
  32.                     }
  33.  
  34.                     if (mySearcher.FindAll().Count == 0)
  35.                     {
  36.                         Console.WriteLine("0 results du!");
  37.                         Console.WriteLine(args[0]);
  38.                     }
  39.                     if (File.Exists("user.txt"))
  40.                     {
  41.                         using (var sr = new StreamReader("user.txt"))
  42.                         {
  43.                             Console.WriteLine(sr.ReadLine());
  44.                             DirectoryEntry usr = new DirectoryEntry(sr.ReadLine());
  45.                             usr.Username = "administrator";
  46.                             usr.Password = "mypassword";
  47.  
  48.                             // Retrieve and write the Path for the object.
  49.                             Console.WriteLine("Path: {0}", usr.Path);
  50.                             // Retrieve and write the Guid for the object.
  51.                             Console.WriteLine("Guid: {0}", usr.Guid);
  52.                             // Retrieve and write the Name for the object.
  53.                             Console.WriteLine("Name: {0}", usr.Name);
  54.                             // Retrieve and write the DN for the object.
  55.                             Console.WriteLine("DN: {0}", usr.Properties["distinguishedName"].Value);
  56.                             try
  57.                             {
  58.                                 //usr.Invoke("SetPassword", "cockfags");
  59.                                 //usr.CommitChanges();
  60.                             }
  61.                             catch (Exception ex)
  62.                             {
  63.                                 Console.WriteLine(ex.Message);
  64.                             }
  65.                             sr.Close();
  66.                         }
  67.                     }
  68.                    
  69.                     File.Delete("user.txt");
  70.                     Console.WriteLine();
  71.                 }
  72.  
  73.                 catch (Exception ex)
  74.                 {
  75.                     Console.WriteLine(ex.Message);
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 Console.WriteLine("0 arguments, noob");
  81.                 Console.ReadKey();
  82.             }
  83.         }
  84.     }
  85. }
Add Comment
Please, Sign In to add comment