NetUserChangePassword Module not found??

G

Guest

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
 
A

Armin Zingler

AndyL said:
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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top