-
January 9th, 2012, 03:26 PM
#1
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.
-
January 9th, 2012, 06:50 PM
#2
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 06:55 PM.
-
January 10th, 2012, 10:41 AM
#3
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?
-
January 10th, 2012, 05:05 PM
#4
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
-
January 11th, 2012, 01:07 AM
#5
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.
-
January 20th, 2012, 07:24 PM
#6
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?
-
December 6th, 2012, 01:45 AM
#7
Re: DSQuery in C#?
Hi mwpeck,
Did you managed to find any for your original query?
-
December 10th, 2012, 04:02 PM
#8
Re: DSQuery in C#?
Originally Posted by idrisgani
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|