Happy New Year to all my assembly friends.

I am having much trouble with the NetUserEnum Function.

My code is as follows:

entriesread			dd ?
totalentries dd ?
user_name LPWSTR ?

invoke NetUserEnum,NULL,0,FILTER_NORMAL_ACCOUNT,addr user_name,
MAX_PREFERRED_LENGTH, addr entriesread,
addr totalentries,NULL
      .IF eax==ERROR_ACCESS_DENIED
invoke ShellAbout,hWin,addr AccessDenied,addr AboutMsg,NULL
    .elseif eax==NERR_InvalidComputer
invoke ShellAbout,hWin,addr InvalidComputer,addr AboutMsg,NULL
    .elseif eax==NERR_GroupNotFound
invoke ShellAbout,hWin,addr GroupNotFound,addr AboutMsg,NULL
    .elseif eax==ERROR_MORE_DATA
invoke ShellAbout,hWin,addr MoreData,addr AboutMsg,NULL
.else
push ebx
xor ebx,ebx
push esi
mov esi,user_name
cmp ebx,entriesread
jae skip
shownext:
invoke MessageBoxW,0,addr user_name,0,0
add ebx,1
add esi,4
cmp ebx,entriesread
jb shownext
skip:
pop esi
pop ebx


Ok, so it gets through the error checks ok, but when I invoke the MessageBox, it does not display the user name correctly, only some squares.  It iterates through the loop the correct number of times.

What am I missing here?

Wongdai
Posted on 2006-01-01 05:04:52 by WongDai
Try changing user_name LPWSTR ? to user_name  USER_INFO_0 <>

PS: Wish U all a happy new year :D
Posted on 2006-01-01 06:21:38 by lone_samurai5
Thanks - but no cigar.  ;-)

Exactly the same result.

Wongdai
Posted on 2006-01-01 06:44:17 by WongDai
If no-one can see the problem, does anyone have any code that uses this function (NetUserEnum) that they could lend me?

Wongdai
Posted on 2006-01-01 19:10:16 by WongDai
invoke MessageBoxW,0,addr user_name,0,0

bufptr, On return a pointer to the return information structure is returned in the address pointed to by bufptr.

You need to dereference the returned pointer first.

Regards,  P1  8)
Posted on 2006-01-01 21:55:43 by Pone
Thanks, but...

I'm sorry, I am very newb at this.

How do I achieve this dereferencing of the pointer?

Wongdai
Posted on 2006-01-01 23:25:19 by WongDai
invoke MessageBoxW,0,user_name,0,0
Posted on 2006-01-02 03:35:18 by ti_mo_n
If I remove the addr (i.e. invoke MessageBoxW,0,user_name,0,0) I get an error on compile "INVOKE argument type mismatch : argument : 2".

I image this is because user_name is defined as:
user_name USER_INFO_0 <>

Yes?

So I tried before calling MessageBoxW to
mov esi,user_name

and then

invoke MessageBoxW,0,esi,0,0)

but I still get pretty much the same results as when I started, i.e. the message that it displays is just boxes.

I am obviously not good at this, but am determined not to give up.

Any other ideas please?

Wongdai


Posted on 2006-01-02 07:07:05 by WongDai
BTW, user_name is a pointer to an array of pointers to USER_INFO_0 structures.

shownext:
    mov eax,
    invoke MessageBoxW,0,eax,0,0


This will fix your code.

When you get into COM interfaces, you will need to know how and when to dereference your data.

Regards,  P1  8)
Posted on 2006-01-02 11:35:29 by P1

invoke MessageBoxW,0,user_name,0,0

He was using esi as his loop pointer.

Regards,  P1  8)
Posted on 2006-01-02 11:37:38 by P1
Thanks P1

I will try that when I get home tonight.  Sounds like I was on the right track?  (....but would never have actually got there.  ;0(  )

Wongdai
Posted on 2006-01-02 18:07:35 by WongDai
P1

You are a bliddy genius!  It works!

Now I just have to work out why.
;-)

Thanks

wongdai
Posted on 2006-01-03 03:17:11 by WongDai
P1,  You are a bliddy genius!  It works!
Then this board is full of geniuses.  I was just the first one to answer.

Remember to do this as well:
bufptr
Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the function fails with ERROR_MORE_DATA.


Regards,  P1  8)
Posted on 2006-01-03 12:44:41 by P1
Ah, ok thanks

I would probably have forgotten to do this.

Wongdai
Posted on 2006-01-03 18:52:20 by WongDai