DSQuery in C#?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: DSQuery in C#?

  1. #1
    Join Date
    May 2008
    Posts
    84

    DSQuery in C#?

    How would I convert this command line (from a .bat) into something I could use in C#?

    Code:
    dsquery user forestroot -samid "%%d" | dsget user -display -upn  -office -tel -mobile -dept | FIND /V "dsget"
    I am not familiar with bat scripting in the slightest, the above does what I want it to but I really don't understand what keywords in the command do what......if possible though I do need to get that working in c#, so what c# functionality would I want to look for and are there any tutorials on using it? I know there is a DSQuery function in c#, I just can't find very good examples on its usage.

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: DSQuery in C#?

    Hoping it wont be too difficult.. dsquery is a tool to query active directory services.. I've never done it myself but the following article on querying anything about AD in C# is well rated and should be of use:

    http://www.codeproject.com/KB/system...thingInAD.aspx
    Last edited by cjard; January 9th, 2012 at 05:55 PM.
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  3. #3
    Join Date
    May 2008
    Posts
    84

    Re: DSQuery in C#?

    That looks like a great C# ActiveDirectory resource, however after looking through it myself the only relevant section to what I am trying to do is the "Active Directory Users Tasks" section (last one at the end), and there do not seem to be any functionality around using dsquery/dsget to look up a user, it all seems focused around normal administrative tasks (adding/removing a user, locking/unlocking a user, etc).

    Anyone have any more resources I can search through or know of how to do this?

  4. #4
    Join Date
    Dec 2011
    Posts
    61

    Re: DSQuery in C#?

    Your command contains pipe ("|"), so the best you can achieve through c# is maybe sth. like this:

    Code:
                Process p = new Process();
                p.StartInfo.UseShellExecute = true;
                p.StartInfo.RedirectStandardOutput = false;
                p.StartInfo.CreateNoWindow = false;
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.Arguments = "/c \"dsquery user forestroot -samid \"%%d\" | dsget user -display -upn  -office -tel -mobile -dept | FIND /V \"dsget\"\"";
                p.Start();
                p.WaitForExit();
    This will open a new console window and display the result. Problem is that you cannot read the output.

    Your alternative will be to use either some PowerShell script to achieve the same result and call the script from c#, or use DirectoryService namespace in .net framework.
    This will open

  5. #5
    Join Date
    May 2008
    Posts
    84

    Re: DSQuery in C#?

    Thanks Silent, using the DirectoryService namespace is sort of what I'm looking for. Ideally, I want to get the same information that the command in my original post gets, but preferably, through C#, not through a command line.

    The only problem is I only have a minor understanding of AD, and have never used the DirectoryService namespace, so I have a hard time understanding exactly how the command works, and so far a better understanding of DirectoryService, but not enough to really do anything on my own yet.

  6. #6
    Join Date
    May 2008
    Posts
    84

    Re: DSQuery in C#?

    Any other tips? From what I can understand, I basically need to look up some Active Directory info using something along the lines of DSQuery, is that built-in C# by default or something I would need to find a library for?

  7. #7
    Join Date
    Apr 2008
    Posts
    38

    Re: DSQuery in C#?

    Hi mwpeck,

    Did you managed to find any for your original query?

  8. #8
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,217

    Re: DSQuery in C#?

    Quote Originally Posted by idrisgani View Post
    Hi mwpeck,

    Did you managed to find any for your original query?
    Search bing or google for "getting user information from DirectoryService in C#"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center