I am using DirectoryServices and the WinNT: // provider to connect to a remote computer. Then I check the group membership information and maybe add or remove a domain user from the specified local group.
I managed to get all this code to work without a hitch using the vb.net console application, and when communicating with my local mailbox or with any field in which my account is registered, I have administrator rights.
the code:
string strUserPath = "WinNT://DomainName/someuser,user";
DirectoryEntry deComputer = new DirectoryEntry("WinNT://" + Computername + ",computer");
deComputer.RefreshCache();
DirectoryEntry deGroup = deComputer.Children.Find("administrators", "group");
IEnumerable members = deGroup.Invoke("members", null);
List<DirectoryEntry> r = new List<DirectoryEntry>();
foreach (object o in members)
{
DirectoryEntry deMember = new DirectoryEntry(o);
r.Add(deMember);
}
deGroup.Invoke("Add", strUserPath);
deGroup.CommitChanges();
deGroup.Invoke("Remove", strUserPath);
deGroup.CommitChanges();
, - ASP.Net, Impersonate web.config. , , , / :
DirectoryEntry deComputer = new DirectoryEntry("WinNT://" + Computername + ",computer", username, password);
- . Username deComputer, , . , , , - .
, , . , ASP.Net , .
, LogonAPI (advapi32.dll → LogonUser call) , , WindowsIdentitiy deComputer. , , , OLE...
, . .
- -
, Windows, , , . SQL, . , , , -.