web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Problems to run methods ShellExecute on process Batch

(0) ShareShare
ReportReport
Posted on by 10
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


*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at

    Yes, you can't use WinAPI in batch sessions. Note that if the exe file is written in .NET, you might be able to simply to use its types directly inside AX process through .NET Interop. It would have many advantages, for example for exception handling.

  • 5400 Profile Picture
    7,162 on at

    Yes, WinAPI is client side API. you can not execute on server.  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans