Announcement

Collapse
No announcement yet.

Restart or Refresh Installer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            You can try
            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

            Comment


            • #7
              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."

              Comment


              • #8
                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

                Comment


                • #9
                  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 ?

                  Comment


                  • #10
                    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

                    Comment


                    • #11
                      Ok, great, thank you Anders!

                      Comment


                      • #12
                        Just so you know, I've updated my EnVar plugin and added an update function so that you can refresh environment variables for the installer process, for example if %path% was changed externally while the installer is still running .
                        "Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
                        NSIS 3 POSIX Ninja
                        Wiki Profile

                        Comment

                        Working...
                        X
                        😀
                        🥰
                        🤢
                        😎
                        😡
                        👍
                        👎