No announcement yet.

PHP and ReadCustomerData

  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP and ReadCustomerData

    Hi to everyone,

    I want to pass a variable to the exe using ReadCustomerData.
    I searched online and i found something but not seems to working.

    NSIS allows you to insert data on to the back of their exe files and then allows you to be able to read that data back during installation: How do I ...

    echo "mydata:testvariable">>setup.exe;

    I want the user when access the page downloads the exe and the variable have passed in the installer.
    Any help is appreciated

  • #2
    So, does setup.exe have the data embedded when you download it or is this a server issue?
    IntOp $PostCount $PostCount + 1


    • #3
      Hi Anders,
      Thanks for the reply.
      I don't know how to pass the parameter to exe with php and download it.


      • #4
        If this is a PHP question then this is not the right place to ask questions...
        IntOp $PostCount $PostCount + 1


        • #5
          xliner78, not quite sure what you want

          PHP script is something that runs on a server. NSIS installer runs on the local computer.

          But if you actually want to invoke a PHP script on the server, from your local NSIS installer, then you have to send a HTTP request to the server and store/evaluate the corresponding HTTP response. Parameters may be passed in the "query string" part of the URL.

          Look into the Inetc plug-in!


          If you actually want the installer EXE to have the "customer data" built-in, it would be a pretty bad idea to just append this extra data to the finished EXE file. Instead, pass it to MakeNSIS via /D switch when you compile the installer! For example, if you pass /DFoo=Bar to MakeNSIS when compiling the installer, then you can get the passed value ("Bar") by using ${Foo} placeholder inside the installer script.
          My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
          My source of inspiration:


          • #6
            Anders is not actually a php question.
            Because i also don't know how to pass the parameter testvariable inside the script.
            I read the documentation but i still cannot make it working?


            • #7
              Originally Posted by xliner78 View Post
              Anders is not actually a php question.
              Because i also don't know how to pass the parameter testvariable inside the script.
              I read the documentation but i still cannot make it working?
              If it is not a PHP question, why did you include PHP in the thread title?

              I'll ask again, when you download the .exe from the server, is your data appended to the file or not? Check with a hex editor. We cannot continue until you answer this question...
              IntOp $PostCount $PostCount + 1


              • #8
                Hi Anders,
                Now i understand.
                When the file downloaded there is nothing appended.My problem is how to append it.
                How to append the data manually on my computer?
                I already tried to open the exe with notepad (with SetCompress off)
                I added in the end of file mydata:testvariable and the installed destroyed
                Thanks for you helping me Anders


                • #9
                  You cannot edit .exe files in notepad, use a hex editor. If you just want to append a string you can start cmd.exe and type "echo Hello World >> MySetup.exe".
                  IntOp $PostCount $PostCount + 1


                  • #10
                    Hi Anders.
                    Thanks for the help .
                    I finally found how to also edit it with php on the fly without changing the installer.exe every time.
                    Here is the full solution
                    Here is the php code you will need
                    $txt ="mydata:testvariable";
                    $filename = "installer.exe";
                    $outputfilename = "exportedexename.exe";

                    header("Content-Type: application/octet-stream");
                    header("Content-Disposition: attachment; filename=\"" . basename($outputfilename) . "\";" );
                    header("Content-Transfer-Encoding: binary");

                    Add this function to your script
                    Function ReadCustomerData
                    ; arguments
                    Exch $R1 ; customer data magic value
                    ; locals
                    Push $1 ; file name or (later) file handle
                    Push $2 ; current trial offset
                    Push $3 ; current trial string (which will match $R1 when customer data is found)
                    Push $4 ; length of $R1

                    FileOpen $1 $EXEPATH r

                    ; change 1024 here to, e.g., 2048 to scan the last 2Kb of EXE file
                    IntOp $2 0 - 1024
                    StrLen $4 $R1

                    FileSeek $1 $2 END
                    FileRead $1 $3 $4
                    StrCmp $3 $R1 found
                    IntOp $2 $2 + 1
                    IntCmp $2 0 loop loop

                    StrCpy $R1 ""
                    goto fin

                    IntOp $2 $2 + $4
                    FileSeek $1 $2 END
                    FileRead $1 $3
                    StrCpy $R1 $3

                    Pop $4
                    Pop $3
                    Pop $2
                    Pop $1
                    Exch $R1

                    And to get the appended data use this
                    Push "mydata:"
                    Call ReadCustomerData
                    Pop $R1
                    StrCmp $R1 "" 0 +3

                    Where $R1 is your appended data.