Solved

How to close Adobe Reader in code?

Posted on 2007-03-28
4
184 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

757 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

22 Experts available now in Live!

Get 1:1 Help Now