Changing Windows NT Password Progmatically

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

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:
Share on facebook
Share on twitter
Share on linkedin


The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job