Old 15th November 2018, 18:01   #1
benjasperson
Junior Member
 
Join Date: Oct 2018
Posts: 7
Restart or Refresh Installer

Is there a way to restart or refresh the installer? I don't know what my underlying issue is. I'm trying to get my installer to install SQL Server (if not installed) and build a database. As long as SQL Server is there when the installer starts, the database is built as expected. It won't build the database on a single run if it needs to install SQL Server first. However, if I run it once to install SQL Server, and then a second time to build the database, everything works fine.

I've tried using Sleep after installing SQL Server, but that doesn't help. I even made a console app that waits for a few seconds and opens the installer. I have my installer execute (using Exec) this app and then Quit. As expected, the installer installs SQL server, opens the console app, and closes the installer (the dialog disappears). After a few seconds, the app starts up the installer again. The installer recognizes that the new SQL Server instance exists (it runs a repair without issues), but it still won't use the instance to build my database unless I manually close and restart the installer.

Here's the error text I get when I cannot build the database:

SQLCMD.EXE - Application Error
The application was unable to start correctly (0xc000007b)

I can easily generate this error buy trying to open sqlcmd after uninstalling all instances of SQL Server.

What is happening when I manually close and restart that is not happening when I programmatically close and restart? How can I make sure that SQL Server is ready to be used after installing it?

I'm guessing that the system doesn't know my installer has installed SQL Server until the installer COMPLETELY closes, but I don't know what to do about it.
benjasperson is offline   Reply With Quote
Old 15th November 2018, 18:27   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,926
Something related to %path%?

Starting something from Explorer gives you the new %path% (if somebody modified it) but restarting the installer from itself will not.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 27th November 2018, 16:19   #3
benjasperson
Junior Member
 
Join Date: Oct 2018
Posts: 7
Solution

Thank you, Anders! You got me heading in the right direction. Since the PATH variables weren't updated, SQLCMD could not be executed. I was however, able to execute a "where" search for sqlcmd and find it that way. Essentially what I did was this:

code:
Section
nsExec::ExecToStack 'where sqlcmd.exe /r "$PROGRAMFILES64"'
Pop $0
${If} $0 = 0 ;check errors
Pop $0
${StrLoc} $1 $0 "sqlcmd.exe" ">" ;get location of "sqlcmd.exe" in "where" result
${If} $1 > 1
IntOp $1 $1 + 10 ;to move to end of "sqlcmd.exe"
StrCpy $0 $0 $1 ;copy string up to "sqlcmd.exe"
DetailPrint $0
Goto end
${Else}
Goto error
${EndIf}
${Else}
Goto error
${EndIf}

error:
;handel error

end:
SectionEnd



The StrLoc Function and macro came from here. I also used this Trim function, though I'm not certain it was necessary.
benjasperson is offline   Reply With Quote
Old 27th November 2018, 20:52   #4
nickdollahz
Junior Member
 
Join Date: Apr 2018
Posts: 11
Interesting solution. I've run into this problem as well. I ended up just hardcoding in the paths for the sqlcmd.exe for each version of SQL 08R2,2012,2014,2016,2017 that I install. Although your solution allows you to install it to a custom location within Programfiles. You could remove the /r and then open it up to all locations.

Ideally you can look into refreshing the paths during runtime. That would be the best solution.
nickdollahz is offline   Reply With Quote
Old 27th November 2018, 23:08   #5
benjasperson
Junior Member
 
Join Date: Oct 2018
Posts: 7
I initially tried it without the /r before I realized that "by default, the search is done in the current directory and in the PATH". I believe I need the recursive search, since sqlcmd won't be in either place. If there is a way to search everywhere, it would still be faster to restrict the search program files.

I do agree it would be better to refresh the paths.

Thanks for the comments.
benjasperson is offline   Reply With Quote
Old 27th November 2018, 23:27   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,926
You can try
Quote:
System::Call 'SHELL32::RegenerateUserEnvironment(*p,i1)i'
after installing the thing that changes %path% but before you try to execute it.

Use the EnVar plug-in if you want to update %path% in the registry yourself.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 1st December 2018, 12:49   #7
trarbish
Junior Member
 
Join Date: Dec 2018
Posts: 3
I have the same problem.
Anders, how should I use this line?
System::Call 'SHELL32::RegenerateUserEnvironment(*p,i1)i'

Should I just insert it in my script?
I tried to run it just in cmd and had the following:
"The filename, directory name, or volume label syntax is incorrect."
trarbish is offline   Reply With Quote
Old 1st December 2018, 13:37   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,926
Yes just put it in a Section before you Exec. I did not test so I'm not sure if it actually works.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 1st December 2018, 21:03   #9
trarbish
Junior Member
 
Join Date: Dec 2018
Posts: 3
Smile

Yes, it works like a charm! Thanks a lot!

How do you learn about this command? What do parameters (*p,i1,i') mean in the command ?
trarbish is offline   Reply With Quote
Old 2nd December 2018, 04:23   #10
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,926
This function is undocumented but you can look at the implementation in ReactOS if you are curious. I don't know what Microsoft names the parameters, I just looked at ReactOS/Wine.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd December 2018, 12:22   #11
trarbish
Junior Member
 
Join Date: Dec 2018
Posts: 3
Ok, great, thank you Anders!
trarbish is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Tags
database, refresh, restart

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