|
|
 |
Author |
Message |
user__2006

|
Posted: .NET Base Class Library, get SID information |
Top |
I have a program that will save an user SID information in a Database.
So, I would like to know, how to list all users ( not groups ) of a selected machine ( can be a domain controller or not ) and get SID information
Tks!!
.NET Development17
|
|
|
|
 |
TaylorMichaelL

|
Posted: .NET Base Class Library, get SID information |
Top |
To get the list of users on a machine you'll need to use either WMI or AD. There have been plenty of postings and sample code for this on the forums so do a search and you'll find the answer. As for getting the SID you can use the SecurityIdentifier class in combination with NTAccount to get the user and their SID for storage.
Michael Taylor - 11/27/06
|
|
|
|
 |
user__2006

|
Posted: .NET Base Class Library, get SID information |
Top |
I am using DirectoryEntry, System.DirectoryServices
But 'obVal' always return NULL...
DirectoryEntry root = new DirectoryEntry();
root.Path = "WinNT://MyMACHINENAME";
object obVal = root.Properties["objectSid"].Value;
|
|
|
|
 |
TaylorMichaelL

|
Posted: .NET Base Class Library, get SID information |
Top |
The problem is that all you've done so far is get access to the machine. You haven't requested the users associated with the machine so you can enumerate them. Unfortunately unless you're running AD this can get a little difficult because the WinNT provider does not support searching directory (from what I understand).
An easier route would be to use WMI to get the list of users and their SID value.
//When connecting as someone else use the options parameter
//ConnectionOptions options = new ConnectionOptions(); //options.Username = ; //options.Password = ; ManagementScope scope = new ManagementScope(
+ Environment.MachineName +
); ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_UserAccount WHERE Disabled <> TRUE"); ManagementObjectSearcher search = new ManagementObjectSearcher(scope, query); ManagementObjectCollection results = search.Get(); foreach (ManagementObject result in results) { Console.WriteLine(result.Properties["SID"].Value); };
Michael Taylor - 12/1/06
|
|
|
|
 |
user__2006

|
Posted: .NET Base Class Library, get SID information |
Top |
OK
However, this only seems to work to list SIDs of my own computer. It does not list SIDs of other network computers.
When I call the method as follows EnumShares("\\MyComputerName") it works fine. However when I call it EnumShares("\\OtherComputer") I get the following error:
Denied Access. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Tks!
ConnectionOptions oConn = new ConnectionOptions();
System.Management. ManagementScope oMs = new System.Management.ManagementScope(
+ "OtherMachineName" +
, oConn);
System.Management. ObjectQuery oQuery = new System.Management.ObjectQuery("SELECT * FROM Win32_UserAccount WHERE Disabled <> TRUE");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs,oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach (ManagementObject oReturn in oReturnCollection)
{
Console.WriteLine(oReturn.Properties["SID"].Value);
}
|
|
|
|
 |
TaylorMichaelL

|
Posted: .NET Base Class Library, get SID information |
Top |
You specified the ConnectionOptions parameter but you didn't specify any credentials. You must specify a valid UN/PWD that has the necessary access rights on the remote machine. Try an admin account first to verify it works. The admin account must be valid on the other computer.
Michael Taylor - 12/7/06
|
|
|
|
 |
|
|