Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
QuestionBook Recommendations Pin
Aaron Schaefer29-Aug-06 8:48
Aaron Schaefer29-Aug-06 8:48 
QuestionPutting a copyright symbol in a label Pin
Ista29-Aug-06 8:45
Ista29-Aug-06 8:45 
AnswerRe: Putting a copyright symbol in a label Pin
Jun Du29-Aug-06 9:04
Jun Du29-Aug-06 9:04 
AnswerRe: Putting a copyright symbol in a label Pin
Ravi Bhavnani29-Aug-06 12:34
professionalRavi Bhavnani29-Aug-06 12:34 
QuestionDisable Tab clicks Pin
Saamir29-Aug-06 8:24
Saamir29-Aug-06 8:24 
AnswerRe: Disable Tab clicks Pin
ventomito29-Aug-06 9:20
ventomito29-Aug-06 9:20 
QuestionLogin for application Pin
vineas29-Aug-06 6:36
vineas29-Aug-06 6:36 
AnswerRe: Login for application Pin
Not Active29-Aug-06 10:01
mentorNot Active29-Aug-06 10:01 
<br />
[DllImport("advapi32.dll", SetLastError = true)]<br />
        public static extern bool LogonUser(String lpszUsername, <br />
            String lpszDomain, String lpszPassword,<br />
            int dwLogonType, int dwLogonProvider, ref IntPtr phToken);<br />
        <br />
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]<br />
        public extern static bool CloseHandle(IntPtr handle);<br />
<br />
 private bool LogonUser()<br />
{<br />
    IntPtr tokenHandle = new IntPtr(0);<br />
    const int LOGON32_PROVIDER_DEFAULT = 0;<br />
    const int LOGON32_LOGON_INTERACTIVE = 3;<br />
<br />
    tokenHandle = IntPtr.Zero;<br />
    // Get the domain to authenticate on from the config<br />
    string DomainName = ConfigurationManager.AppSettings["Domain"];<br />
<br />
    try<br />
    {<br />
        // Call LogonUser to obtain a handle to an access token.<br />
        if(LogonUser(txtName.Text, DomainName, txtPwd.Text,<br />
            LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,<br />
            ref tokenHandle))<br />
        {<br />
            // Since login succeeded, set the current<br />
            // principal to the logged in user<br />
            WindowsIdentity WinIdentity = new WindowsIdentity(tokenHandle);<br />
            System.Threading.Thread.CurrentPrincipal =<br />
                new WindowsPrincipal(WinIdentity);<br />
<br />
            return true;<br />
        }<br />
        else<br />
        {<br />
            return false;<br />
        }<br />
    }<br />
    catch(SystemException)<br />
    {<br />
        MessageBox.Show("Domain could not be found. Check network connection.");<br />
        DialogResult = DialogResult.Abort;<br />
    }<br />
    catch(Exception ex)<br />
    {<br />
        ExceptionPolicy.HandleException(ex, "Unhandled Exception Policy");<br />
        DialogResult = DialogResult.Abort;<br />
    }<br />
    finally<br />
    {<br />
        // Clean up resources<br />
        if( tokenHandle != IntPtr.Zero )<br />
            CloseHandle(tokenHandle);<br />
    }<br />
}<br />



only two letters away from being an asset

GeneralRe: Login for application Pin
vineas29-Aug-06 10:58
vineas29-Aug-06 10:58 
GeneralRe: Login for application Pin
Not Active29-Aug-06 11:05
mentorNot Active29-Aug-06 11:05 
QuestionStupid, stupid problem Pin
gantww29-Aug-06 5:48
gantww29-Aug-06 5:48 
QuestionRe: Stupid, stupid problem Pin
Nader Elshehabi29-Aug-06 6:32
Nader Elshehabi29-Aug-06 6:32 
QuestionMultiple instance of Control (Class Library) Pin
Maddie from Dartford29-Aug-06 5:09
Maddie from Dartford29-Aug-06 5:09 
QuestionGetWindowText API? Pin
wbjohnson29-Aug-06 4:58
wbjohnson29-Aug-06 4:58 
AnswerRe: GetWindowText API? Pin
Dave Kreskowiak29-Aug-06 7:30
mveDave Kreskowiak29-Aug-06 7:30 
GeneralRe: GetWindowText API? Pin
wbjohnson29-Aug-06 7:39
wbjohnson29-Aug-06 7:39 
GeneralRe: GetWindowText API? Pin
Dave Kreskowiak29-Aug-06 9:20
mveDave Kreskowiak29-Aug-06 9:20 
GeneralRe: GetWindowText API? Pin
wbjohnson29-Aug-06 12:03
wbjohnson29-Aug-06 12:03 
QuestionApplication Blocks Help Pin
Brendan Vogt29-Aug-06 4:39
Brendan Vogt29-Aug-06 4:39 
AnswerRe: Application Blocks Help Pin
Not Active29-Aug-06 10:11
mentorNot Active29-Aug-06 10:11 
GeneralRe: Application Blocks Help Pin
Brendan Vogt29-Aug-06 20:35
Brendan Vogt29-Aug-06 20:35 
GeneralRe: Application Blocks Help Pin
Not Active30-Aug-06 3:11
mentorNot Active30-Aug-06 3:11 
Questionsql timeout Pin
JacquesDP29-Aug-06 4:27
JacquesDP29-Aug-06 4:27 
AnswerRe: sql timeout Pin
Baj2229-Aug-06 5:12
Baj2229-Aug-06 5:12 
GeneralRe: sql timeout Pin
JacquesDP29-Aug-06 5:33
JacquesDP29-Aug-06 5:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.