Why does the following code crash sometimes when I run it?
code:
Name "EnumUsersGroups"
OutFile "EnumUsersGroups.exe"
!macro GetUserGroups SERVER_NAME USERNAME GROUP_ARRAY_NAME
Push $R0
Push $R1
Push $R2
Push $R3
# NET_API_STATUS NetUserGetLocalGroups(
# __in LPCWSTR servername,
# __in LPCWSTR username,
# __in DWORD level,
# __in DWORD flags,
# __out LPBYTE *bufptr,
# __in DWORD prefmaxlen,
# __out LPDWORD entriesread,
# __out LPDWORD totalentries
# );
# $R0 buffer with an array of LOCALGROUP_USERS_INFO_0 structures
# $R1 holds the number of entries processed
System::Call 'netapi32::NetUserGetLocalGroups(w "${SERVER_NAME}", w "${USERNAME}", \
i 0, i 0, *i .R0, i ${NSIS_MAX_STRLEN}, *i .R1, *i .R2) i .R3'
StrCpy $R2 $R0 ; Needed to free the buffer later
# check for error
StrCmp $R3 0 +1 +2
System::Call "*$R0(w.R3)"
# Cleanup
StrCmp $R2 0 +2
System::Call 'netapi32.dll::NetApiBufferFree(i R2) i .R0'
Pop $R3
Pop $R2
Pop $R1
Pop $R0
!macroend
!define GetUserGroups "!insertmacro GetUserGroups"
ShowInstDetails show
Page instfiles
Section ""
${GetUserGroups} "" "Tobbe" GroupArray
SectionEnd