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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Active Discussion

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

  • Martin Dráb Profile Picture
    239,932 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sanhthosh.Kumar.K Profile Picture

Sanhthosh.Kumar.K 2

#2
Raed Salah Bzour Profile Picture

Raed Salah Bzour 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans