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)

Shell execute in server

(0) ShareShare
ReportReport
Posted on by 2,903

Hi All,

I have a requirement to run a command from the batch processing, since we do not have shellExecute command in server winapi class, I am calling the shell execute method in server method of my batch class but it is throwing an error that CIL cannot run on client. could anyone know how to run the command in batch processing.

thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    Have you tried adding the shellExecute to WinAPIServer with the appropriate InteropPermissions?

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    Probably this blog post might help you: "How to execute an external process from a batch" ?

  • MuthukumaranAX Profile Picture
    2,903 on at

    thanks for you reply, is it good to change the standard method?

  • MuthukumaranAX Profile Picture
    2,903 on at

    Hi Oleg, thanks for your response, i tried this code but this is not working if i run from batch process.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    I would't recommend changing standard method. I think it's better to create a new class with static server method for this call.

  • Martin Dráb Profile Picture
    237,920 Most Valuable Professional on at

    MuthukumaranAX, unfortunately we can't help you if you don't tell us anything more than "this is not working".

  • MuthukumaranAX Profile Picture
    2,903 on at

    Martin, I did the following things on this issue

    1. created a new class which extends winapiserver and added shellExecute method with server static, while running this code as batch I am getting run-time errors

    i) server cannot execute the client code.

    ii) the function 'ShellExecuteExW' has caused an error

    2. I have the code from the url (ax4dev.wordpress.com/2012/07/20/shell-execute-on-batch-server-2/)  and tried to run as batch job, I did not get any errors but no files are getting copied to the local system

    pls let me know what am i missing or how can i do this

    thanks.

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    Consider carefully the security context under which any external process runs.  If your AOS is setup as a domain account, then that is straight forward.  If, on the other hand, your AOS is running under Network Service, then access to off-machine resources occurs under the SERVERNAME$ domain computer account, which must be granted access to those resources.

  • Martin Dráb Profile Picture
    237,920 Most Valuable Professional on at

    You mustn't use any client code; that's the main bug that you have to fix. I don't know your code so I can't tell you where exactly you have client-bound code.

    Also, don't extend WinAPIServer class. It has no advantage, because there are no instance methods to inherit.

  • MuthukumaranAX Profile Picture
    2,903 on at

    Hi Martin,

    below is the code which i am using as a batch processing for copying the files.

    can you tell me am i missing some thing on the below code.

    #WinAPI

       System.Diagnostics.Process              process;

       System.Diagnostics.ProcessStartInfo     processStartInfo;

       ;

       new InteropPermission(InteropKind::ClrInterop).assert();

       process = new System.Diagnostics.Process();

       processStartInfo = new System.Diagnostics.ProcessStartInfo();

       processStartInfo.set_FileName(@"C:\WINDOWS\System32\ftp.exe");

       processStartInfo.set_Arguments(_fileName);

       processStartInfo.set_WorkingDirectory(_localFolder);

       process.set_StartInfo(processStartInfo);

       process.Start();

       //process.WaitForExit();

       process.Close();

    thanks.

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