Search code examples
vbscriptnsisbinary-searchwsh

vbscript not working from within nsis installer but it works when i manually run it


I have a VBscript that searches for a string in an sqlite file (plaintext). It is run by my NSIS installer to determine install parameters.

When i run the script from the command line it all works as planed and finds the string it was looking for in the file. But when i run it via ExecWait from within the nsis installer all the sudden it says it can't find the string anymore. It doesn't say it can't open the file or any other error, it just returns that the string is not present.

Here's the exec from the nsis script:

ExecWait `"$SYSDIR\wscript.exe" "$PLUGINSDIR\myscript.vbs" "success" "failure" "done" "1"` $2

Here's the block that is causing me so much trouble:

Function LookforValue(strFile)
    iStatus = 0
    Done = false
    Const ForReading = 1

    MsgBox(S_PATTERN)
    MsgBox(F_PATTERN)   
    MsgBox(D_PATTERN)       

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    objFile = 0
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)
        Do Until objFile.AtEndOfStream
            strSearchString = objFile.ReadLine
            colMatchesS = InStr(strSearchString,S_PATTERN)
            colMatchesF = InStr(strSearchString,F_PATTERN)
            colMatchesD = InStr(strSearchString,D_PATTERN)

            If colMatchesS > 0 Then
                iStatus = 2
                exit do
            End If

            If colMatchesF > 0 Then
                iStatus = 3
                exit do
            End If

            If colMatchesD > 0 Then
                iStatus = 4
                exit do
            End If

        Loop
    objFile.Close



    LookforValue = iStatus

End Function

FYI i'm using VBscript instead of nsis commands because nsis was getting fussy about the file being locked by another process.


Solution

  • I didn't really solve the problem but i concluded it was because i was trying to use OpenTextFile on a binary file that just coincidentally didn't want to work when the other script was running it.