Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

Problems to run methods ShellExecute on process Batch

$
0
0
Many times we execute code that behaves differently when running batch. This often may force us to change the code and use other classes.
I will detail the issues of running the ShellExecute method of class Winapi. The code hadto download data from external table in other on AX:

Public void ImportCustInvoiceTable()
{
    InteropPermission    perm = new InteropPermission( InteropKind::ClrInterop );
    str                  _str;
    ;

    perm.assert();

    _str = curExt();
    winapi::shellExecute(“InsertCustInvoice.exe',curExt());
}

I resolved the problem using  the classes System.Diagnostics.Process  and  System.Diagnostics.ProcessStartInfo.

The result was:

server static void ImportCustInvoiceTableForBatch()

{
        System.Diagnostics.Process              process;
        System.Diagnostics.ProcessStartInfo   processStartInfo;       
        Boolean        start;
        FileName    _fileName
        ;

        // Assert CLRInterop permission
        new InteropPermission(InteropKind::ClrInterop).assert();


        _fileName = “InsertCustInvoice.exe';

        //Se instancia ProcessStartInfo en el que se pasa la ruta del ejecutable y los parámetros necesarios
        processStartInfo    = new System.Diagnostics.ProcessStartInfo(_fileName,curExt());

        // Se instancia la clase Process
        process             = new System.Diagnostics.Process();


         // Use the system shell to execute the process
        processStartInfo.set_UseShellExecute(false);

        // Attach the starting information to the process
        process.set_StartInfo(processStartInfo);

        // Start the process and wait for it to complete
        start = process.Start();

        process.Close();

        CodeAccessPermission::revertAssert();        

}

I hope you find it useful



Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>