Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.DirectoryServices;
- using System.IO;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length != 0)
- {
- try
- {
- DirectoryEntry entry = new DirectoryEntry("GC://mydomain.dk");
- entry.Username = "administrator";
- entry.Password = "mypassword";
- DirectorySearcher mySearcher = new DirectorySearcher(entry);
- mySearcher.Filter = "(sAMAccountName= " + args[0] + ")";
- foreach (SearchResult result in mySearcher.FindAll())
- {
- if (!File.Exists("user.txt"))
- {
- using (var sw = new StreamWriter("user.txt"))
- {
- sw.WriteLine(result.GetDirectoryEntry().Path);
- sw.Close();
- }
- }
- }
- if (mySearcher.FindAll().Count == 0)
- {
- Console.WriteLine("0 results du!");
- Console.WriteLine(args[0]);
- }
- if (File.Exists("user.txt"))
- {
- using (var sr = new StreamReader("user.txt"))
- {
- Console.WriteLine(sr.ReadLine());
- DirectoryEntry usr = new DirectoryEntry(sr.ReadLine());
- usr.Username = "administrator";
- usr.Password = "mypassword";
- // Retrieve and write the Path for the object.
- Console.WriteLine("Path: {0}", usr.Path);
- // Retrieve and write the Guid for the object.
- Console.WriteLine("Guid: {0}", usr.Guid);
- // Retrieve and write the Name for the object.
- Console.WriteLine("Name: {0}", usr.Name);
- // Retrieve and write the DN for the object.
- Console.WriteLine("DN: {0}", usr.Properties["distinguishedName"].Value);
- try
- {
- //usr.Invoke("SetPassword", "cockfags");
- //usr.CommitChanges();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- sr.Close();
- }
- }
- File.Delete("user.txt");
- Console.WriteLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- else
- {
- Console.WriteLine("0 arguments, noob");
- Console.ReadKey();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment