How to change the windows user password with VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thijsdemaa
    New Member
    • Apr 2012
    • 3

    How to change the windows user password with VB.NET

    Hi,
    I want to change the windows user password in a VB.net Module...
    Just change it, how can i do that?
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    You're going to need to use the NetUserChangePa ssword Win32 API call for this to work. Here's a simple demonstration on using that API:

    Code:
    Public Class Class1
    	<DllImport("netapi32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode)> _
    	Public Shared Function NetUserChangePassword( _
    	     <MarshalAs(UnmanagedType.LPWStr)> ByVal Domain As String, _
    	     <MarshalAs(UnmanagedType.LPWStr)> ByVal User As String, _
    	     <MarshalAs(UnmanagedType.LPWStr)> ByVal OldPass As String, _
    	<MarshalAs(UnmanagedType.LPWStr)> ByVal NewPass As String) As Integer
    	End Function
    	
    	Public Sub ChangePassword(ByVal domain As String, 
    		ByVal username As String,
    		ByVal oldPassword As String,
    		ByVal newPasword As String)
    		
    		Try
    			NetUserChangePassword(domain, username, oldPassword, newPasword)
    		Catch ex As Exception			
    			Throw
    		End Try
    		
    		
    	End Sub
    End Class
    You're be using the System.Runtime. InteropServices

    That should get you started down the right path

    Comment

    • thijsdemaa
      New Member
      • Apr 2012
      • 3

      #3
      Thank you!
      But is there a way to do that, without knowing the old password?

      Comment

      • PsychoCoder
        Recognized Expert Contributor
        • Jul 2010
        • 465

        #4
        No there isn't. This is starting to sound like a malicious act the more that get's asked.

        Comment

        • thijsdemaa
          New Member
          • Apr 2012
          • 3

          #5
          No, no, not at all!
          It's a little program I have made to level up the privacy of my computer.
          I wanted to generate a random code as a password that would be sent to my email...

          Comment

          Working...