Changing Windows NT Password Progmatically

Changing Windows NT Password Progmatically

Question:
How can I change my Windows NT server password through a program?

Answer:
Actually, this is rather simple. However, heed the following precaution from the MSDN documentation on this function:

“A server or domain can be configured to require a user to log on before changing the password on a user account. In that case, only members of the Administrators or Account Operators local group or the user himself can change the password for a user account. If logging on is not required, the user can change the password for any user account, as long as the user knows the current password.”

IN A FORM:Private Sub Command1_Click()   Dim p_strUserName                As String   Dim p_strOldPass                 As String   Dim p_strNewPass                 As String   Dim p_blnRtn                     As Boolean      p_strUserName = Me.txtUserName.Text   p_strOldPass = Me.txtOldPassword.Text   p_strNewPass = Me.txtNewPassword.Text      p_blnRtn = Module1.SetPassword("", _                                  p_strUserName, _                                  p_strOldPass, _                                  p_strNewPass)   If p_blnRtn = False Then      MsgBox "Failed to reset the password for '" & _         p_strUserName & "'."   Else      MsgBox "Successfully changed password!"   End If   End SubIN A BAS or CLS FILE:Option ExplicitPublic Declare Sub CopyMem Lib "kernel32" Alias _   "RtlMoveMemory" (pTo As Any, pFrom As Any, _   ByVal lCount As Long)Private Declare Function NetApiBufferFree _   Lib "netapi32.dll" _   (ByVal lngPtrBuffer As Long) As LongPrivate Declare Function NetUserChangePassword _   Lib "netapi32" _   (psDomainName As Byte, _    psUserName As Byte, _    psOldPass As Byte, _    psNewPass As Byte) As LongPublic Function SetPassword(ByVal DomainName As String, _                            ByVal UserName As String, _                            ByVal OldPassword As String, _                            ByVal NewPassword As String) As Boolean   Dim p_lngRtn                        As Long   Dim p_bytDomainName()               As Byte   Dim p_bytUserName()                 As Byte   Dim p_bytOldPassword()              As Byte   Dim p_bytNewPassword()              As Byte   Dim p_strNewPassword                As String      ' Convert the domain name to a byte array   If Len(Trim$(DomainName)) = 0 Then      p_bytDomainName = vbNullChar   Else      p_bytDomainName = DomainName & vbNullChar   End If      p_bytUserName = UserName & vbNullChar   p_bytOldPassword = OldPassword & vbNullChar   p_bytNewPassword = NewPassword & vbNullChar      p_lngRtn = NetUserChangePassword(p_bytDomainName(0), _                                    p_bytUserName(0), _                                    p_bytOldPassword(0), _                                    p_bytNewPassword(0))   If p_lngRtn = 0 Then      SetPassword = True   Else      SetPassword = False   End If      UserName = p_bytUserName   OldPassword = p_bytOldPassword   p_strNewPassword = p_bytNewPassword   If Right$(p_strNewPassword, 1) = vbNullChar Then      p_strNewPassword = Mid$(p_strNewPassword, 1, Len(p_strNewPassword) - 1)   End If      If p_strNewPassword <> NewPassword Then      SetPassword = False   End If   End Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes