Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to close Adobe Reader in code?

Posted on 2007-03-28
4
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

636 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