Archive: List of SQL Servers from a Text File to a ListBox


List of SQL Servers from a Text File to a ListBox
Dear Friends,

I want the users to show a drop-down list filled with list of sql servers.
I'm able to extract the list of servers and write it into a text file by executing the OSQL command from NSIS. Now how to proceed further to make them available in a drop-down list box.

My text file "ServerList.txt" is like this:

Servers:
(local)
JACK
ALICE
ALEX\SQLEXPRESS
JULIE
TOM\SQLEXPRESS
MAINSERVER (local)
JACK
ALICE
HARRY
SERVER
SERVER1
SUPPORT1
SUPPORT2
SWAPAN
SWAPAN\SKDSSE
SWAPAN\SQLEXPRESS

plz. note there is white space above the line "Servers:". Attached the text file.

I want to know how to read from the actual data i.e.
(local)
and not start from the 1st line:
Servers:
And then how to trim a line and read it, then moving to next line and perform the same job, until the end of data.

Then want to make them join to a single variable with a pipe (|)separtor between each server names something like:

StrCpy $SQLList $SQLList|$R0


If some For Next is to be done to pad the data to the variable SQLList, then please show me with the above scenario.

Regards,


!define CUST_INI "$PLUGINSDIR\custom.ini"

!include "TextFunc.nsh"
!insertmacro TrimNewLines

outfile 'test.exe'

page custom CreateCustom
page instfiles

section

sectionend

Function .onInit
InitPluginsDir
Call ReadServers
WriteINIStr "${CUST_INI}" "Settings" "NumFields" "1"
WriteINIStr "${CUST_INI}" "field 1" "type" "droplist"
WriteINIStr "${CUST_INI}" "field 1" "left" "10"
WriteINIStr "${CUST_INI}" "field 1" "right" "-10"
WriteINIStr "${CUST_INI}" "field 1" "top" "10"
WriteINIStr "${CUST_INI}" "field 1" "bottom" "-10"
WriteINIStr "${CUST_INI}" "field 1" "state" "$R2"
WriteINIStr "${CUST_INI}" "field 1" "Listitems" "$R2|$R3"
FunctionEnd

Function ReadServers
StrCpy $R2 ""
StrCpy $R3 ""
FileOpen $R0 "listofservers.txt" r
start:
FileRead $R0 "$R1"
${TrimNewLines} "$R1" "$R1"
StrCmp "$R1" "" start
StrCpy "$R2" "$R1"
loop:
FileRead $R0 "$R1"
IfErrors done
${TrimNewLines} "$R1" "$R1"
StrCpy "$R3" "$R3|$R1"
goto loop
done:
FileClose $R0
FunctionEnd

Function CreateCustom
push $0
InstallOptions::dialog "${CUST_INI}"
pop $0
pop $0
FunctionEnd

Great Red Wine! Thanks thats what I was looking for. You must be surprised I was thinking of you while posting this issue, but was not sure of your reply as the title relates to SQL.
I will work on it and will come up with new issues for you!
Thanks again!

Regards,