Solved

How to close Adobe Reader in code?

Posted on 2007-03-28
4
185 Views
Last Modified: 2013-11-25
Hi,

I am using following code to print a pdf file from a windows app. The requirement is to close the acrobat view after the print. When I step through it, the

  MyProcess.CloseMainWindow()
will do the trick, but in real time, it dose not close the viewer.

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
           Dim MyProcess As New System.Diagnostics.Process
           MyProcess.StartInfo.FileName = "c:\OrderForm.pdf"
           MyProcess.StartInfo.UseShellExecute = True
        MyProcess.StartInfo.Verb = "Print"
        MyProcess.Start()
        MyProcess.CloseMainWindow()
        Me.Close()
    End Sub
0
Comment
Question by:ommer
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18821523
You may just need a small pause before closing the app...

        MyProcess.Start()
        System.Threading.Thread.Sleep(2000) ' two second pause
        MyProcess.CloseMainWindow()
        Me.Close()
0
 

Author Comment

by:ommer
ID: 18822919
Ok, I can see your point. But how to pause?

I have treid
 MyProcess.WaitForExit(10000)

The me.close has been delayed for 10 seconds, but the viewer did not close.

Thanks!
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 18823887
What do you mean "But how to pause?"...

I put it right there in the code example I gave:

        MyProcess.Start() ' start the process
        System.Threading.Thread.Sleep(10000) ' ten second pause
        MyProcess.CloseMainWindow() ' NOW try closing the main window?
        Me.Close() ' close the form

I suppose you can do it this way as well:

        MyProcess.Start()
        MyProcess.WaitForExit(10000)
        If Not MyProcess.HasExited Then
            MyProcess.CloseMainWindow()
        End If
        Me.Close()
0
 

Author Comment

by:ommer
ID: 18824143
That worked (the first one).
I thought you meant to insert a pause between CloseMainWindow() and me.close().
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now