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(txtLoginName.Text,
txtDomain.Text, txtPassword.Text, (int)
LOGON32_LOGON_NETWORK, (int)LOGON32_PROVIDER_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);
WindowsPrincipal wp = new
WindowsPrincipal(l_Wid);
System.Threading.Thread.CurrentPrincipal = wp;
HttpContext.Current.User =
wp;
//////////////////////////
// Declare the logon types as constants
const long LOGON32_LOGON_INTERACTIVE = 2;
const long LOGON32_LOGON_NETWORK = 3;
// Declare the logon providers as constants
const long LOGON32_PROVIDER_DEFAULT = 0;
const long LOGON32_PROVIDER_WINNT50 = 3;
const long LOGON32_PROVIDER_WINNT40 = 2;
protected
System.Web.UI.WebControls.TextBox TextBox1;
const long LOGON32_PROVIDER_WINNT35 = 1;
[DllImport("advapi32.dll",EntryPoint
= "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.DirectoryServices.DirectoryEntry usr = new
DirectoryEntry(entryPC.Path, txtUsername.Text,
txtPassword.Text);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>EHsuCqGmSUa45Rjc8gxZLg==</Id>
.