Old 20th April 2010, 13:21   #1
xreboot
Junior Member
 
Join Date: Apr 2010
Posts: 8
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
xreboot is offline   Reply With Quote
Old 20th April 2010, 13:31   #2
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
http://nsis.sourceforge.net/User_Man...rate_all_users
jpderuiter is offline   Reply With Quote
Old 20th April 2010, 14:19   #3
xreboot
Junior Member
 
Join Date: Apr 2010
Posts: 8
Only crashing my installer.
Any variables i have to define before executing the macro?
xreboot is offline   Reply With Quote
Old 20th April 2010, 15:05   #4
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
The script mentioned in that wiki page makes uses of the NSISArray plugin and header - make sure the compiler can find those.
Animaether is offline   Reply With Quote
Old 20th April 2010, 15:25   #5
xreboot
Junior Member
 
Join Date: Apr 2010
Posts: 8
yes i'm not getting any error in compiling my script aswell i'm using
code:
!include "NSISArray.nsh"
xreboot is offline   Reply With Quote
Old 20th April 2010, 15:43   #6
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
what if you try this?
PHP Code:
!include "LogicLib.nsh"

OutFile "test.exe"

Section
SectionEnd

RequestExecutionLevel admin

Function .onInit
  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
  
${ForEach} $9 0 $R2 1
    System
::Call "*$R0(w.R9)"
    
MessageBox MB_OK "[$R9]"
    
IntOp $R0 $R0 4
  
${Next}
  
System::Call 'netapi32.dll::NetApiBufferFree(i R8)i .R1'
FunctionEnd 
Animaether is offline   Reply With Quote
Old 20th April 2010, 15:53   #7
xreboot
Junior Member
 
Join Date: Apr 2010
Posts: 8
then i get a popup of all users. Is it also possible to display them in a list?
xreboot is offline   Reply With Quote
Old 20th April 2010, 16:10   #8
xreboot
Junior Member
 
Join Date: Apr 2010
Posts: 8
i got it

code:
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



Ty for the help!
xreboot is offline   Reply With Quote
Old 20th April 2010, 16:24   #9
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
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
Animaether is offline   Reply With Quote
Old 20th April 2010, 16:37   #10
xreboot
Junior Member
 
Join Date: Apr 2010
Posts: 8
one more issue...

i do this now:

code:

${ForEach} $9 0 $R2 + 1
System::Call "*$R0(w.R9)"
!define user$9 $R9
IntOp $R0 $R0 + 4
${Next}



But i cant recall my defined users.

Is there any workaround?
xreboot is offline   Reply With Quote
Old 20th April 2010, 17:06   #11
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
Quote:
Originally Posted by xreboot View Post
one more issue...

code:

!define user$9 $R9



But i cant recall my defined users.

Is there any workaround?
Defines 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)
Animaether is offline   Reply With Quote
Old 21st April 2010, 09:04   #12
CancerFace
Senior Member
 
Join Date: Apr 2006
Posts: 289
Send a message via ICQ to CancerFace
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 ...
code:
!define NERR_Success 0
!define NERR_More_Data 234
!define strNET_DISPLAY_USER '(w,w,i,w,i,i)i'


Then the macro:
code:
!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


Call the macro (for the local machine):
code:
StrCpy $1 0
!insertmacro EnumLocalUsers "" LocalUsers $1
${If} $1 = 1
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "Error on the API call!"
${EndIf}


and if I debug I get all the local users in the array object:
code:
NSISArray:ebug /NOUNLOAD LocalUsers


Hope this helps,
CF

Last edited by CancerFace; 21st April 2010 at 09:25.
CancerFace is offline   Reply With Quote
Old 22nd April 2010, 11:33   #13
xreboot
Junior Member
 
Join Date: Apr 2010
Posts: 8
Alright, i got it now, but how can i exclude stuff like SUPPORT_388945a0
?

Last edited by xreboot; 22nd April 2010 at 13:01.
xreboot is offline   Reply With Quote
Old 22nd April 2010, 14:22   #14
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 22nd April 2010, 14:43   #15
xreboot
Junior Member
 
Join Date: Apr 2010
Posts: 8
got it all fixed .

For those with a similar problem:
http://pastebin.com/R4tfTHhW
xreboot is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump