C # modifying the domain account password
Directoryentry entry1 = new directoryentry ("LDAP: //" + "Domain Name", "User Name", "password ");
Directorysearcher searcher1 = new directorysearcher (entry1 );
Searcher1.filter = "(samaccountname =" + "username" + ")";
Searchresult result1 = searcher1.findone ();
"Domain Name" format (Dc = Baidu, Dc = com)
C # Get the User Name of the current domain
Ensure your project has referenced DLL "system. Management", then CSHARP codes as below:
Using system. diagnostics;
Using system. Management;
Namespace workrecord
{
Class currentuser
{
Public static string getcurrentuser ()
{
String currentuser = NULL;
Foreach (PROCESS p in process. getprocesses ())
{
Currentuser = getprocessusername (P. ID );
If (currentuser! = "System" & currentuser! = NULL & currentuser! = String. Empty)
Break;
}
Return currentuser;
}
Private Static string getprocessusername (int pid)
{
String theuser = NULL;
Selectquery query1 = new selectquery ("select * From win32_process where processid =" + PID );
Managementobjectsearcher searcher1 = new managementobjectsearcher (query1 );
Try
{
Foreach (managementobject disk in searcher1.get ())
{
Managementbaseobject inpar = NULL;
Managementbaseobject outpar = NULL;
Inpar = disk. getmethodparameters ("getowner ");
Outpar = disk. invokemethod ("getowner", inpar, null );
Theuser = outpar ["user"]. tostring ();
Break;
}
}
Catch
{
Theuser = "system ";
}
Return theuser;
}
}