locked
Check Windows Username and Password RRS feed

  • Question

  • Hi,

      Im using C#.Net 2003,im using windows 2000 operating system.. i retrieved all the available windows user by using the following code and listed in the listbox..

     

    private void button2_Click_1(object sender, System.EventArgs e)

    {

    using(DirectoryEntry root = new DirectoryEntry("WinNT://node-10"))

    {

    foreach (DirectoryEntry child in root.Children)

    {

    if (child.SchemaClassName == "User")

    {

    listBox1.Items.Add(child.Name);

    }

    }

    }

    }

     

    Actually i want to check is it the right user or not from the C#.Net by programmatically..

    in textbox1 im entering the username and

    in textbox2 im entering the password

    on clicking the ok button it should check whether the entered username and password are the right one or not,if it is the right one, then in messagebox("Valid user") else in messagebox("Invaliduser").How should i achieve this one...plz help me..its urgent...

     

    rgrds

    Senthil

    Tuesday, May 1, 2007 6:58 AM

Answers

  • Please view the KB article How to validate Windows user rights in a Visual Basic .NET or Visual Basic 2005 application.


      Write code to validate the Windows user in your Visual Basic .NET application:


      You can use the LogonUser Win32 API to verify the user name and password. The LogonUser function is declared in the Advapi32.dll library. You can call the LogonUser function from your Visual Basic .NET application by using the Declare statement.

    You must pass the domain name, the user name, and the password to the LogonUser function. The LogonUser function validates the user by using these parameters and then returns a Boolean value. If the function succeeds, you receive a handle to a token that represents the Windows user. The WindowsIdentity object uses this token to represent the Windows user in your Visual Basic .NET or Visual Basic 2005 application. The WindowsPrincipal object uses this WindowsIdentity object to verify the Windows user's user rights.

    To write code that implements validation in your Visual Basic .NET or Visual Basic 2005 application, Please follow those steps in the KB article above.

    Tuesday, May 1, 2007 4:22 PM
  • Hi

      Thanks for your valuable reply,i got the answer with help of your link..on implementing that code i got only message as "a required privilege is not held by the client" and then i add the users in local policies in the Administrative tools which is in the control panel..Everything is working fine, but what the problem is that once i added the user in the local policies i need to restart my computer to take effect..Is it possible to take effect without restarting system? or it can be achive by programmmatically without restarting or not? Plz reply me..

     

    Regards

      Kanna...

    Wednesday, May 2, 2007 12:29 PM

All replies

  • Please view the KB article How to validate Windows user rights in a Visual Basic .NET or Visual Basic 2005 application.


      Write code to validate the Windows user in your Visual Basic .NET application:


      You can use the LogonUser Win32 API to verify the user name and password. The LogonUser function is declared in the Advapi32.dll library. You can call the LogonUser function from your Visual Basic .NET application by using the Declare statement.

    You must pass the domain name, the user name, and the password to the LogonUser function. The LogonUser function validates the user by using these parameters and then returns a Boolean value. If the function succeeds, you receive a handle to a token that represents the Windows user. The WindowsIdentity object uses this token to represent the Windows user in your Visual Basic .NET or Visual Basic 2005 application. The WindowsPrincipal object uses this WindowsIdentity object to verify the Windows user's user rights.

    To write code that implements validation in your Visual Basic .NET or Visual Basic 2005 application, Please follow those steps in the KB article above.

    Tuesday, May 1, 2007 4:22 PM
  • Hi

      Thanks for your valuable reply,i got the answer with help of your link..on implementing that code i got only message as "a required privilege is not held by the client" and then i add the users in local policies in the Administrative tools which is in the control panel..Everything is working fine, but what the problem is that once i added the user in the local policies i need to restart my computer to take effect..Is it possible to take effect without restarting system? or it can be achive by programmmatically without restarting or not? Plz reply me..

     

    Regards

      Kanna...

    Wednesday, May 2, 2007 12:29 PM
  • After Security Policy is changed, it will take effect when next time system refreshes security setting automatically.

    For workstation and server, system refreshes security security setting automatically at 90 minutes interval.

    For domain control, system refreshes security setting automatically at 5 minutes interval.

    No matter whether Security Policy is changed, system refreshes security setting automatically at 16 hours interval.

     

     By the way, the following commands can update group policy immediately.

     GPUpdate /force

     Secedit.exe

     http://support.microsoft.com/kb/227302

     http://technet2.microsoft.com/WindowsServer/zh-CHS/Library/02e1b4dc-00a7-41b1-8610-38d43d5e5d5d2052.mspx?mfr=true

     

    But you'd better log off or restart your computer to take it effect after Local security policy is changed.

     

    Thank you for sharing your valuable experience with us here!

    Thursday, May 3, 2007 12:48 PM