Hi,
You dont need to authenicate again to access "X" pc. You
can use current session and can access "X"(if you have
permissions).
IntPtr token = new IntPtr(0);
bool isValidUser = LogonUser(txtLo ginName.Text,
txtDomain.Text, txtPassword.Tex t, (int)
LOGON32_LOGON_N ETWORK, (int)LOGON32_PR OVIDER_DEFAULT, ref
token);
if(isValidUser == false)
{
Msg.Text = "Wrong user
name or password<br>";
}
else
{
IntPtr token2 = new IntPtr
(token.ToInt32( ));
WindowsIdentity l_Wid =
new WindowsIdentity (token2);
WindowsPrincipa l wp = new
WindowsPrincipa l(l_Wid);
System.Threadin g.Thread.Curren tPrincipal = wp;
HttpContext.Cur rent.User =
wp;
//////////////////////////
// Declare the logon types as constants
const long LOGON32_LOGON_I NTERACTIVE = 2;
const long LOGON32_LOGON_N ETWORK = 3;
// Declare the logon providers as constants
const long LOGON32_PROVIDE R_DEFAULT = 0;
const long LOGON32_PROVIDE R_WINNT50 = 3;
const long LOGON32_PROVIDE R_WINNT40 = 2;
protected
System.Web.UI.W ebControls.Text Box TextBox1;
const long LOGON32_PROVIDE R_WINNT35 = 1;
[DllImport("adva pi32.dll",Entry Point
= "LogonUser" )]
private static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider ,
ref IntPtr phToken);
-----Original Message-----
Dear All,
I would like to perform a simple task by program (VB.Net
or VC#.Net).
When a user logins the windows and try to run my program,
how can I use his login information (username and
password) to authenicate against another PC, e.g. using
DirectoryEntry object?
I have these lines of code, but it needs the user to
enter username and password in Textboxes txtUsername and
txtPassword respectively. I would like to use the current
login session information to do the job instead..System.Directo ryServices.Dire ctoryEntry usr = new
DirectoryEntry( entryPC.Path, txtUsername.Tex t,
txtPassword.Tex t);string strUserID;
try
{
strUserID = usr.NativeGuid;
MessageBox.Show ("Login correct!");
}
catch
{
MessageBox.Show ("Login Incorrect!");
}
Thanks for your help.
--------------------------------
From: Stephen Yip
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>EHsuCqGmSU a45Rjc8gxZLg==</Id>
.