Another way to verify the domain
Write this article, I hope that the master can write similar solutions with the AD-related class or name space under the .NET. Requirements: This system is not in any of two domains, but requires verification of logging accounts (like UserName @ Dmain) in one of two domains. Can't establish a trust domain. Tip: Use the NET USE command to log in to the return value and hide the window of the command prompt.
/ ** /
///
public
String
STARTAPP
String
IP,
String
Domain,
String
Strname,
String
Strpassword
{Process App = New Process (); String Netcmd = "USE" IP "// IPC $" Strpassword "/ User:" " " // " strname; processstartinfo info = new processstartinfo (@" net ", netCMD); info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.UseShellExecute = false; info.CreateNoWindow = true; app.StartInfo = info; app.Start (); app.WaitForExit (); StreamReader reader = app. STANDARDOTPUT; STRING OK = Reader.Readline (); string no = app.standarderror.readline (); string [] appstr = new string [2]; appstr [0] = OK; appstr [1] = no; this.exitApp (ip); return appstr;}
/ ** /
///
Void
EXITAPP
String
IP)
{Process app = new process (); string netcmd = "use" ip "// ipc $ / del"; processstartinfo info = new processstartinfo (@ "net", netcmd); info.createnowindow = true; app.startinfo = INFO; app.start (); app.waitforeXIT ();
/ ** /
///
public
Bool
Checkdomain
String
IP,
String
Domain,
String
Strname,
String
Strpassword
{String [] Appstr = this.startApp (IP, Domain, Strname, Strpassword); Bool Checkok = false; if (AppStr [0]! = Null) {Checkok = true;} IF (appstr [1]! = Null) {Checkok = False;} returnick;
Log in the New Year:
String
Domain1
=
System.configuration.configurationSettings.AppSettings [
"
Domain1
"
] .ToString ();
String
IP1
=
System.configuration.configurationSettings.AppSettings [
"
IP1
"
] .ToString ();
String
Domain2
=
System.configuration.configurationSettings.AppSettings ["
Domain2
"
] .ToString ();
String
IP2
=
System.configuration.configurationSettings.AppSettings [
"
IP2
"
] .ToString ();
IF
(Domain)
==
Domain1)
{IF (this.checkdomain (IP1, DOMAIN1, STRNAME, STRPASSWORD == false) {throw new exception ("username or password error");}}
Else
IF
(Domain)
==
Domain2)
{IF (this.checkdomain (IP2, domain2, strname, strpassword == false) {throw new exception ("username or password error");}}
Else
{Throw new Exception ("Fill in the domain is not in the domain, please check if the domain name is wrong");
}
I hope the master can provide a related solution under the AD class.