locked
Executing a Batch file from MS Access RRS feed

  • Question

  •  I am using MS Access and would like to pass an exe name to my code signing cert batch file.  Been trying to figure this one out, but cannot get there.  I created a batch file called. SignFile.bat.  It contains everything I need to sign the file, but I need to pass the exe name to the file.  The exe name has spaces and is supposed to be enclosed in double quotes "Test File Sign.exe" and I thins this is causing me the issue. 

      The SignFile.bat is as follows:

    The SignFile.bat is as follows and is located in C:\Cloud Data\Devl\:

    Where "%~1" should be the file name with the double quotes.

    Signtool sign /f "C:\Cloud Data\Code_Signing_Cert\ISSCodeCert.pfx" /p password /tr http://tsa.starfieldtech.com /td SHA256 "%~1"

    if errorlevel 1 goto error

    goto end

    :error
    echo Failed with error #%errorlevel%.
    exit /b %errorlevel%

    :end
    ==============================
    it should end up being "Dealer 1 Acura_ISS.exe"

    1.  SignPath is where the batch file

    SignPath = CurrentProject.Path & "\SignFiles.bat"

    2.  SignName is where the exe file is located

    SignName = CurrentProject.Path & "\" & rstDelFldr!DlrName & "_ISS\" & rstDelFldr!DlrName & "_ISS.exe"

            SignStr = SignPath + " " + SignName
            Call Shell(SignStr, 1)
    ============================
    I only need to figure out how to pass the SignName into the batch file
    ==============================
    Image
    I removed the cmd.exe from the line.
    Error Message:

    Image
    • Edited by ballj_351 Tuesday, January 1, 2019 6:51 PM Fixed message
    Tuesday, January 1, 2019 6:49 PM

Answers

  • You probably just need to ensure that the path to the .bat file and the target filename are both enclosed in double-quotes within the constructed SignStr;  Something like this:

            SignStr = """" & SignPath & """ """ & SignName & """"
            Call Shell(SignStr, 1)


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by ballj_351 Tuesday, January 1, 2019 9:53 PM
    Tuesday, January 1, 2019 9:01 PM
  • You can wait for the process using the API code found here:

        http://theaccessweb.com/api/api0004.htm
        API: Shell and Wait

    I don't know offhand how to get the return code of the batch file.  I expect it can be done, but I don't have time to do the research right now.  In the worst case, you could have the batch file write the return code out to a file, and after it finishes your code could read that file.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by ballj_351 Wednesday, January 2, 2019 1:24 AM
    Tuesday, January 1, 2019 11:29 PM

All replies

  • You probably just need to ensure that the path to the .bat file and the target filename are both enclosed in double-quotes within the constructed SignStr;  Something like this:

            SignStr = """" & SignPath & """ """ & SignName & """"
            Call Shell(SignStr, 1)


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by ballj_351 Tuesday, January 1, 2019 9:53 PM
    Tuesday, January 1, 2019 9:01 PM
  •   I have been researching for a way to make the VBA code wait until this batch file is complete before going to the next instruction.  Can you let me know and how to get the return code coming back from the batch file.  Thanx in advance.

    Jerry


    Tuesday, January 1, 2019 9:55 PM
  • You can wait for the process using the API code found here:

        http://theaccessweb.com/api/api0004.htm
        API: Shell and Wait

    I don't know offhand how to get the return code of the batch file.  I expect it can be done, but I don't have time to do the research right now.  In the worst case, you could have the batch file write the return code out to a file, and after it finishes your code could read that file.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by ballj_351 Wednesday, January 2, 2019 1:24 AM
    Tuesday, January 1, 2019 11:29 PM