List of all users
Hi there.
I was wondering, for my backup program, if it is possible to get a list of users and use them as variables in cmd or nsis?
So i can backup all of my users with one click.
Thanks in advance.
Rob
Archive: List of all users
List of all users
Hi there.
I was wondering, for my backup program, if it is possible to get a list of users and use them as variables in cmd or nsis?
So i can backup all of my users with one click.
Thanks in advance.
Rob
Only crashing my installer.
Any variables i have to define before executing the macro?
The script mentioned in that wiki page makes uses of the NSISArray plugin and header - make sure the compiler can find those.
yes i'm not getting any error in compiling my script aswell i'm using
!include "NSISArray.nsh"
what if you try this?
FunctionEnd
>
then i get a popup of all users. Is it also possible to display them in a list?
i got it :)
Function users
!insertmacro MUI_HEADER_TEXT "userlist" "overzicht van alle gebruikers"
ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"
System::Call 'netapi32::NetUserEnum(w "\\$0",i 0,i 2,*i .R0,i ${NSIS_MAX_STRLEN}, *i .R1,*i .R2,*i .r1)i .r2'
StrCpy $R8 $R0
IntOp $R2 $R2 - 1
SetOutPath "$INSTDIR\"
StrCpy "$1" "$INSTDIR"
FileOpen "$0" "users.bat" "w"
FileWrite "$0" "$1$\r$\n"
${ForEach} $9 0 $R2 + 1
System::Call "*$R0(w.R9)"
FileWrite "$0" "set user$9=[$R9]$\r$\n"
IntOp $R0 $R0 + 4
${Next}
FileClose "$0"
System::Call 'netapi32.dll::NetApiBufferFree(i R8)i .R1'
FunctionEnd
Not sure why your installer hung/crashed before.. might have been NSISArray - not really needed.. the macro should use a callback function instead and let the user decide what to do with the info. I might propose an edit to that wiki page later.
Anyway - glad it's all sorted :)
one more issue...
i do this now:
${ForEach} $9 0 $R2 + 1
System::Call "*$R0(w.R9)"
!define user$9 $R9
IntOp $R0 $R0 + 4
${Next}
Originally posted by xrebootDefines are created at compile-time, rather than runtime. If you need the list of users the installer is run on, use a variable instead. Or fall back to the text file output and read from that, or use NSISArray to store each user in an array (which the original macro did) :)
one more issue...
!define user$9 $R9
But i cant recall my defined users.
Is there any workaround?
I have not been keeping up with Afro's NSISArray array plugin development, but I am pretty sure that the wiki page macro works with version 1.x ...
Here is what also works with v.2.3 that I just tested:
First some definitions ...
!define NERR_Success 0
!define NERR_More_Data 234
!define strNET_DISPLAY_USER '(w,w,i,w,i,i)i'
!macro EnumLocalUsers SERVER_NAME ARRAY_NAME ERRORFLAG
!define Index "Line${__LINE__}"
StrCpy ${ERRORFLAG} 0
; $R0 gets number of entries, $R1 is an array of NET_DISPLAY_USER structures
System::Call /NOUNLOAD 'netapi32::NetQueryDisplayInformation(w "${SERVER_NAME}",i 1,i 0,i 99, i ${NSIS_MAX_STRLEN},*i .R2,*i .R0)i.r5'
StrCmp $5 ${NERR_Success} ${Index}_No_Error
StrCmp $5 ${NERR_More_Data} ${Index}_No_Error ${Index}_Error
${Index}_Error:
StrCpy ${ERRORFLAG} 1
Goto ${Index}_End
${Index}_No_Error:
StrCpy $R7 $R0
NSISArray::New /NOUNLOAD ${ARRAY_NAME} $R2 2
StrCpy $2 0
${Index}_Feed:
StrCmp $2 $R2 ${Index}_Stop
System::Call '*$R0${strNET_DISPLAY_USER}(.R9,,,,,)'
IntOp $R0 $R0 + 24
NSISArray::Write /NOUNLOAD ${ARRAY_NAME} $2 '$R9'
IntOp $2 $2 + 1
Goto ${Index}_Feed
${Index}_Stop:
NSISArray::FreeUnusedMem /NOUNLOAD
${Index}_End:
System::Call /NOUNLOAD 'netapi32::NetApiBufferFree(i R7)i.r5'
!undef Index
!macroend
StrCpy $1 0
!insertmacro EnumLocalUsers "" LocalUsers $1
${If} $1 = 1
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "Error on the API call!"
${EndIf}
NSISArray::Debug /NOUNLOAD LocalUsers
Alright, i got it now, but how can i exclude stuff like SUPPORT_388945a0
?
v2.3 had a MS VC90 CRT dependency (in its XML manifest) which I've now sorted in v2.4. Let me know if the crashing is fixed.
Stu
got it all fixed :).
For those with a similar problem:
http://pastebin.com/R4tfTHhW