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)

Terminate external program

(0) ShareShare
ReportReport
Posted on by 160

I want to terminate/shut down an external program from C++ after printing a document. When printing a PDF document the program Adobe Reader remains open after printing even if the documents itself are closed.

The code snipplet:

WinAPI::shellExecute(DIRECTORY + "\\" + filename, '', '', "Print");

I have read about WM_QUIT(), Application.Quit(), TerminateApp() and TerminateProcess(), but all seams to require an ID of the opened application. As far as I can see, there is no such ID to be fetched.

Any ideas?

*This post is locked for comments

I have the same question (0)
  • Luegisdorf Profile Picture
    1,930 on at

    hi

     the WinAPI::shellExecute returns an integer gives you the process handle you need.

  • Community Member Profile Picture
    on at

    You can also use the Adobe Reader’s command line switch “/t” which activates the “silent mode” - it will print the file without showing any dialogs, and automatically close when finished. For that, you’ll need to call Adobe Reader’s executable (AcroRd32.exe) with “/t” follwed by PDF file as argument, for example like this:

    WinAPI::shellExecute(
        'C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRd32.exe',
        '/t ' + DIRECTORY + '\\' + filename, '', '');

    AcroRd32.exe can also accept the printer (name, UNC, or IP address) as argument after the filename. It this argument is omitted, then the default printer will be used.

  • Morten Pelle Korsmo Profile Picture
    160 on at

    Thanks both. Yes, the /t worked fine until the last page, which is still open and so the program is. So I'm pretty much where I started.. There must be a way to just terminate an open program or an empty!

  • Luegisdorf Profile Picture
    1,930 on at

    But now if you have the process Id (hwnd), you could use one of your suggest methods (like TerminateProcess(hwnd, 0)), or?

  • Morten Pelle Korsmo Profile Picture
    160 on at

    Honestly, I haven't dived to deep in how to get the hwnd yet. How exactly do I retrieve it from ShellExecute in C++? Do I have to pass a value calling the method or does it return a value without an input parameter? Regarding to MSDN this is a parameter, but the class definition in Ax does not have it.

  • Luegisdorf Profile Picture
    1,930 on at

    I'm a little bit irritated. Tought you use WinAPI::shellExecute(DIRECTORY + "\\" + filename, '', '', "Print"); in AX? And this method returns the hWND

    hwnd = winapi::shellexecute('myprogram');

     However if you use it directly in c++ it's the return value of the shellExecute method too, the first parameter is the hWND of the program which calls the function, this is not an out parameter.

    Hope this clarify a little bit.

  • Morten Pelle Korsmo Profile Picture
    160 on at

    Of cource! This cleared a lot to me! I will look at it. Sorry to irritate you. As you see, I'm kinda new in this game and still has much to learn.

    Thanks a lot and have a nice week end!

  • Tobias Brüggendick Profile Picture
    31 on at

    [quote user="Luegisdorf"]

    hi

    the WinAPI::shellExecute returns an integer gives you the process handle you need.

    [/quote]

    I think you are wrong here. As posted [url=http://dynamics-ax.blogspot.com/2005/12/winapishellexecute-method.html]here[/url] there are only two values which come back from WinAPI::shellExecute:

    0 - Problem

    1 - Launch was ok

    I tested this with opening the internet explorer and i ever got back the value 1 because the IE was opened correctly.

    Best Regards,

    Tobias

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