Archive: System::Call 'netapi32::NetUserEnum'


System::Call 'netapi32::NetUserEnum'
Hey,

I have some trouble using the System::Call 'netapi32::NetUserEnum'!

I need a way to get a list of the local users.
Some months ago "Anders" adviced me to use the System-Plugin:

http://forums.winamp.com/showthread.php?s=&threadid=304642&highlight=exec

I am using the functions written by "CancerFace". This worked fine for a while but once in a while I am running into some kind of memory-leak?!?!
I found the Thread about it:

http://forums.winamp.com/showthread.php?s=&threadid=243303&highlight=EnumerateUsers

I wrote for testing a small installer with a loop. When I set the number of iterations high the error always appears. Is there something I am doing wrong? I am really thankful for any help that you guys can give me.

This is my test-installer:

!include "Sections.nsh"
!include "LogicLib.nsh"
;--------------------------------

Name "One Section"
OutFile "one-section.exe"

;--------------------------------
Var i
Var j

!macro EnumerateUsers SERVER_NAME
messagebox mb_ok|mb_iconexclamation 'Start'
!define Index "Line${__LINE__}"
StrCpy $j 0
Loop:
IntOp $j $j + 1


System::Call 'netapi32::NetUserEnum(w "${SERVER_NAME}",i 0,i 2,*i .R0,i -1, \
*i .R1,*i .R2,*i .r1)i .r2'
StrCpy $R8 $R0
StrCpy $9 0
${Index}-loop:
StrCmp $9 $R2 ${Index}-stop +1
;messagebox mb_ok|mb_iconexclamation 'BEFORE CALL! R0:[$R0]'
System::Call "*$R0(w .R9)"
IntOp $i $9 + 1
IntOp $R0 $R0 + 4
IntOp $9 $9 + 1
Goto ${Index}-loop
${Index}-stop:
System::Call 'netapi32.dll::NetApiBufferFree(i R8)i .R1'

${If} $j < "1000"
goto Loop
${EndIf}
!undef Index
messagebox mb_ok|mb_iconexclamation 'Stop'
!macroend

;--------------------------------

; Sections
Section !Required
!insertmacro EnumerateUsers "\\127.0.0.1"
SectionEnd


System::Call 'netapi32::NetUserEnum(w "${SERVER_NAME}",i 0,i 2,*i .R0,i -1, \
*i .R1,*i .R2,*i .r1)i .r2'
System::Call 'netapi32.dll::NetApiBufferFree(i R0)i .R1'
in a loop does not leak

comment out System::Call "*$R0(w .R9)" and the problem seems to go away(Looking at private bytes in process explorer), not sure why

...but your usage of the resume handle seems wrong, you should do StrCpy $1 0 before the loop and use *i r1 r1 in the function call, not *i .r1

also, $R1 has the count of items you got, not $R2

here is the complete code i'm testing:


Var i
Var j

!macro EnumerateUsers SERVER_NAME
messagebox mb_topmost 'Start'
!define Index "Line${__LINE__}"
StrCpy $j 0
StrCpy $1 0
Loop:
IntOp $j $j + 1

System::Call 'netapi32::NetUserEnum(w "${SERVER_NAME}",i 0,i 2,*i .R0,i -1, \
*i .R1,*i .R2,*i r1 r1)i .r2'
StrCpy $R8 $R0
StrCpy $9 0

${Index}-loop:
StrCmp $9 $R1 ${Index}-stop 0
#System::Call "*$R0(w.R9)" ;uncomment this for leak...
IntOp $i $9 + 1
IntOp $9 $9 + 1
IntOp $R0 $R0 + 4
#DetailPrint "$9==$R1:$R9<<$R0"
Goto ${Index}-loop
${Index}-stop:

System::Call 'netapi32.dll::NetApiBufferFree(i R8)i .R1'



${If} $j < "1000"
goto Loop
${EndIf}
!undef Index
messagebox mb_ok|mb_iconexclamation 'Stop'
!macroend
Section !Required
!insertmacro EnumerateUsers "\\127.0.0.1"
SectionEnd

Hey Anders,

thanks again for looking into it. Really appreciate the fast support in this forum.
I am still looking for a solution.