Solved

have a program that is running as a service do something

Posted on 2003-11-24
4
205 Views
Last Modified: 2010-05-18
i had a request do use acrobat reader to print a .pdf file with vb6
i found that it could be done whit 'shelling' the acrobat reader and sending keystrokes to it
something along the lines of:
dim a as long
a=shell("theacrobatreader with a file",vbminimizednofocus)
sleep 1000
appactivate a
doevents
sendkeys ("^p")
doevents
appactivate ("Print")
doevents
sendkeys("{ENTER}")
but now i am asked to do it with acrobat reader totally invisible
i have found that it is invisible if shelled with vbHide instead of vbminimizednofocus
but now the acrobat reader runs as a service
so anybody any ideas how to make it print when running as a service ?

 
0
Comment
Question by:foxerke
  • 2
4 Comments
 
LVL 2

Expert Comment

by:MaxPol
Comment Utility
Hi,

when you shell acrobat, use the following command line prameters:

acrord32.exe /p /h [you pdf file].

That should do what you need.

No more need to use SendKeys.

Hope this help,

Max
0
 

Author Comment

by:foxerke
Comment Utility
no does not work
the acrobat reader is visible in the taskbar
but i already found the following solution that works:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10

Private Sub Command1_Click()
    ShellExecute Me.hwnd, "print", "c:\test.pdf", vbNullString, vbNullString, 0
End Sub

Private Sub Form_Load()
    'ShellExecute Me.hwnd, "open", "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe", vbNullString, vbNullString, 0
     Shell "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe", vbHide
    'ShellExecute Me.hwnd, "open", "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe", "/h", vbNullString, 0
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Dim a As Long
    a = FindWindow(vbNullString, "Acrobat Reader")
    PostMessage a, WM_CLOSE, 0&, 0&
End Sub

Maxpol
i can do 1 of 2 things:
1) reduce this questions points to 0 and accept it
2)ask support to delete it
please advice
0
 
LVL 2

Accepted Solution

by:
MaxPol earned 500 total points
Comment Utility
As you prefer,

I think that my suggestion should work.

If you open My Computer and then select:

Tools -> Folder Options

select the tab File Types.

Now look for the exstention PDF.

Now in XP, you should select Advanced, in the Actions text box, select print and then on the right select Edit.

What you see in the normal command that will be launched when you use the right mouse button on a pdf and select print.

So it should work, but check your system, could be that a different version of OS or Acrobat reader have different parameters.

Bye,

Max
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

10 Experts available now in Live!

Get 1:1 Help Now