How To Change Network Passwords Under Windows by Using PwdChangePassword in Visual Basic (262656)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows 95
    • the operating system: Microsoft Windows 98
    • the operating system: Microsoft Windows Millennium Edition

This article was previously published under Q262656

SUMMARY

This article describes how you can change network passwords under Microsoft Windows 95, Microsoft Windows 98, and Microsoft Windows Millennium Edition (Me) through the use of Microsoft Visual Basic.

MORE INFORMATION

You can use PwdChangePassword() from Mpr.dll to change the network password under Windows 95/98/Me. If you call this API to change the password, a noncustomizable dialog box appears and prompts the user for password information.

The following sample code demonstrates how to call PwdChangePassword from Visual Basic 6.0 to change the password.

Example

  1. Start Visual Basic. From the File menu, choose New Project. Form1 is created by default.
  2. Add a Command button, Command1, to Form1.
  3. Add the following code to the General Declarations section of Form1:
    Option Explicit
    
     'definitions found in pwdspi.h
     Private Const PS_SYNCMASTERPWD = 3
     Private Const PS_SYNCMASTERPWD_OFF = 0
     Private Const PS_SYNCMASTERPWD_ON = 1
    
    'CHANGEPWDINFO structure is also found in pwdspi.h
    Private Type CHANGEPWDINFO
       lpUserName   As String
       lpPassword   As String
       cbPassword   As Long
    End Type
    
    'function declarations for ascii version
    Private Declare Function PwdChangePasswordA Lib "mpr.dll" ( _
        ByVal lpProvider As String, _
        ByVal hwndOwner As Long, _
        ByVal dwFlags As Long, _
        ByRef lpChangePwdInfo As Any) As Long
    
    Private Declare Function PwdSetPasswordStatusA Lib "mpr.dll" ( _
        ByVal lpProvider As String, _
        ByVal dSyncMasterPWD As Long, _
        ByVal dSyncMasterPWD2 As Long) As Long
    
    
    Private Sub Command1_Click()
    Dim sMsg As Long
    Dim uInfo As CHANGEPWDINFO
    
    'To synchronize network provider password with windows password we
    'need to call PwdSetPasswordStatus. By synchronizing the network
    'provider password we avoid having to change each password separately.
    'Network providers listed in registry at:
    'HKLM/System\CurrentControlSet\Control\PwdProvider
    
    sMsg = PwdSetPasswordStatusA("MSNP32", PS_SYNCMASTERPWD, PS_SYNCMASTERPWD_ON)
    
    If (sMsg) Then
        MsgBox "PwdSetPasswordStatusA failed with error " & sMsg
        Exit Sub
    End If
    
    'Call PwdChangePassword specifying NULL as network provider.
    'This causes windows (non-network) password to be changed and hence
    'all synchronized passwords.
    
    sMsg = PwdChangePasswordA(vbNullString, 0, 0, uInfo)
    
    If (sMsg) Then
        MsgBox "PwdChangePasswordA failed with error" & sMsg
        Exit Sub
    End If
    
    End Sub
    					
  4. Run the application and click the Command1 button.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

177200 How To Programmatically Change Network Password Under Windows 95


Modification Type:MinorLast Reviewed:9/27/2004
Keywords:kbDSWNET2003Swept kbAPI kbKernBase kbnetwork kbSecurity KB262656