Home All Groups Group Topic Archive Search About

NetUserChangePassword Module not found??

Author
20 Jan 2006 2:06 PM
AndyL
Hi,

when i call the NETUserChangePassword from the netapi32.ll I receive "Module
not found" error?

Here my code:

    Private Declare Unicode Function NetUserChangePassword Lib
"netapi32.dll" (ByVal domainname As String, _
                                                                       ByVal
Username As String, _
                                                                       ByVal
OldPassword As String, _
                                                                       ByVal
NewPassword As String) As Long

Sub main
retVal = netUserChangePassword("MyDomain", "MyUser", "OldPassword",
"NewPassword")
End sub

Public Shared Function GetErrorMessage(ByVal errorCode As Integer) As String
        Dim FORMAT_MESSAGE_ALLOCATE_BUFFER As Integer = &H100
        Dim FORMAT_MESSAGE_IGNORE_INSERTS As Integer = &H200
        Dim FORMAT_MESSAGE_FROM_SYSTEM As Integer = &H1000

        Dim messageSize As Integer = 255
        Dim lpMsgBuf As String
        Dim dwFlags As Integer = FORMAT_MESSAGE_ALLOCATE_BUFFER Or
FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS

        Dim ptrlpSource As IntPtr = IntPtr.Zero
        Dim prtArguments As IntPtr = IntPtr.Zero

        Dim retVal As Integer = FormatMessage(dwFlags, ptrlpSource,
errorCode, 0, lpMsgBuf, _
            messageSize, prtArguments)
        If 0 = retVal Then
            Throw New Exception("Failed to format message for error code " +
errorCode.ToString() + ". ")
        End If

        Return lpMsgBuf
    End Function 'GetErrorMessage

Author
20 Jan 2006 2:30 PM
Armin Zingler
Show quote Hide quote
"AndyL" <An***@discussions.microsoft.com> schrieb
> Hi,
>
> when i call the NETUserChangePassword from the netapi32.ll I receive
> "Module not found" error?
>
> Here my code:
>
>    Private Declare Unicode Function NetUserChangePassword Lib
> "netapi32.dll" (ByVal domainname As String, _
>
>  ByVal Username As String, _
>
>  ByVal OldPassword As String, _
>
>  ByVal NewPassword As String) As Long


The type of the function return value should by Integer, not Long. I don't
know if it solves the problem.


Armin
Author
26 Jan 2005 10:20 PM
Crouchie
Why not use WMI to change password instead? A lot simpler

Crouchie1998
BA (HONS) MCP MCSE
Author
27 Jan 2006 5:46 AM
AndyL
Hi,

i wan't to try ADSI. But it doesn't work.
I'm connecting the active directory with:
set oUser = GetObject("WinNT://<domain>/<user>,user",<user>,<oldpassword>)
In the security log i see the logon of the user. Then i will change the
password with the change password mehtod.
call oUSer.changePassword(<oldpassword>,<newpassword>)
This method fails. In the eventlog i see the change password method is
called in the user context of the current user and not in the context of the
connected user.

So the next idea was creating a impersonation (it's working now) and then
call the changepassword Method of the netapi32.dll




Show quoteHide quote
"Crouchie" wrote:

> Why not use WMI to change password instead? A lot simpler
>
> Crouchie1998
> BA (HONS) MCP MCSE
>
>
>