0

I am working on a legacy application which calls CreateProcess method

method1()
{
        BOOL bResult = ::CreateProcess(
        NULL,               // LPCTSTR    
        wctAppPath,         // LPTSTR      lpszCommandLine
        NULL,               // LPSECURITY_ATTRIBUTES lpsaProc
        NULL,               // LPSECURITY_ATTRIBUTES lpsaThread
        FALSE,              // BOOL                  fInheritHandles
        NULL,               // DWORD                 fdwCreate
        NULL,               // LPVOID                lpvEnvironment
        NULL,               // LPCTSTR               lpszCurDir
        &stStatusInfo,      // LPSTARTUPINFO         lpsiStartInfo
        &stProcInfo         // LPPROCESS_INFORMATION lppiProcInfo
    );
}

wctAppPath value : (folderPath\test.bat ..\excel.xls) this CreateProcess trigger bat file that will launch vbscript and passed excel file is modified.

Once this method1() ends, they are calling CreateProcess() again in method2() to open the same excel file.

method2()
{
  BOOL bResult = ::CreateProcess(
        NULL,               // LPCTSTR    
        wctAppPath,         // LPTSTR      
        NULL,               // LPSECURITY_ATTRIBUTES lpsaProc
        NULL,               // LPSECURITY_ATTRIBUTES lpsaThread
        FALSE,              // BOOL                  fInheritHandles
        NULL,               // DWORD                 fdwCreate
        NULL,               // LPVOID                lpvEnvironment
        NULL,               // LPCTSTR               lpszCurDir
        &stStatusInfo,      // LPSTARTUPINFO         lpsiStartInfo
        &stProcInfo         // LPPROCESS_INFORMATION lppiProcInfo
        );
}

Here wctAppPath is (excelInstallationPath\EXCEL.exe folderPath\excelFile.xls)

Once all the main function ends, the required modified excel in stored in Documents folder not in the actual given path. Actual given excel is not modified at all.

I have commented the method2 and tried. Expected excel appears in given path.

usmanharoon
  • 173
  • 2
  • 13
  • Why is this tagged VBScript? – Rno Oct 09 '20 at 13:06
  • 1
    There is no guarantee that once Excel is run, it will save its output to the same file as the input. The user can tell Excel to save the output to any file they want. Also, you can't use `CreateProcess()` to execute a `.bat` file directly. Use `ShellExecute/Ex()` instead for that. Otherwise, use `CreateProcess()` to run `cmd.exe /C` instead, giving it the `.bat` path and input values as parameters to `cmd.exe`. – Remy Lebeau Oct 09 '20 at 16:54

1 Answers1

0

Legacy application is CATIA. In V5, CATScriptUtilities::ExecuteScript is used to call catvba. In V6, we can use the same API to call catvba. It works fine. There is no need to call .bat->.vba->.catvba

usmanharoon
  • 173
  • 2
  • 13