These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to close Acrobat after printing pdf, within VB6

smohrmax
Registered: Sep 25 2009
Posts: 5

Hi All,

First timer here and not sure where to post this question.....

I have a VB6 project that I have a need to print a PDF that is already existing.

I can actually do the "printing" part of this by using "shellexecute".

Here is my question...
How do I "close" the Acrobat application after "printing" is complete, without user intervention?

Thanks,
Steve

amitylounge
Registered: Sep 25 2009
Posts: 2
I am also seeking answer to this question....please reply...
smohrmax
Registered: Sep 25 2009
Posts: 5
This is what I had to do... must be a better way... oh well

after the "ShellExecute" returns, I go into a "Sleep" function, then I "Shell" to a batch file process that kills the task which is determined by the Window Title. (My PDF's that I am printing are not manuals, they are only a few pages. So my Sleep time is not too long).


The VB6 code in below....

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

.... Sub ....
x = ShellExecute(Me.hWnd, "PRINT", CommonDialog1.FileName, vbNullString, vbNullString, 0)
Sleep (40000)
x = Shell("C:\Storefront\Reports\endjob.bat", vbNormalFocus)
... End Sub ...

-- - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


This is the code that is contained in the batch file.... 1 line....

taskkill /F /FI "WINDOWTITLE eq Adobe*"



Thanks
Steve
patricksnead24
Registered: Sep 27 2009
Posts: 2
Comments would be helpful for me if it had some useful information. I hope for some good comments. Will you give some information about it ?


Thanks,

[url=http://www.babyphon-babyphone.de]Babyphone[/url]

smohrmax
Registered: Sep 25 2009
Posts: 5
The VB6 code is below.... with comments.. Hope this helps others...

' This declares the "Sleep" function

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


.... Sub ....
'
' I am using a "CommonDialog1" that will open the folder and list the filenames available
' for selection. I select the file then the "ShellExecute" takes over.
' ShellExecute will perform the "PRINT" action on the "CommonDialog1.Filename".
' CommonDialog1.Filename contains the Filename I am printing, (yourPDFfilename.pdf)
'
x = ShellExecute(Me.hWnd, "PRINT", CommonDialog1.FileName, vbNullString, vbNullString, 0)

' When ShellExecute returns, I call the "Sleep" function, and this will delay the program 40000 milliseconds. This is enough time for the reports to print.

Sleep (40000)

' when the delay is complete, the "Shell" calls a DOS batch (.bat) file that will "Kill" the Adobe Reader "Task" by looking at the WINDOW TITLE equal the Adobe

x = Shell("C:\Storefront\Reports\endjob.bat", vbNormalFocus)


... End Sub ...

-- - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This is the code that is contained in the batch file "C:\Storefront\Reports\endjob.bat".... 1 line....

taskkill /F /FI "WINDOWTITLE eq Adobe*"


-- - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BELOW IS THE INFO ON Taskkill or see this link
http://technet.microsoft.com/en-us/library/bb491009.aspx

Taskkill
Ends one or more tasks or processes. Processes can be killed by process ID or image name.

Syntax
taskkill [/s Computer] [/u Domain\User [/p Password]]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t]

Top of page

Parameters
/s Computer : Specifies the name or IP address of a remote computer (do not use backslashes). The default is the local computer.

/u Domain \ User : Runs the command with the account permissions of the user specified by User or Domain\User. The default is the permissions of the current logged on user on the computer issuing the command.

/p Password : Specifies the password of the user account that is specified in the /u parameter.

/fi FilterName : Specifies the types of process(es) to include in or exclude from termination. The following are valid filter names, operators, and values.

Name
Operators
Value

Hostname
eq, ne
Any valid string.


Status
eq, ne
RUNNING|NOT RESPONDING

Imagename
eq, ne
Any valid string.


PID
eg, ne, gt, lt, ge, le
Any valid positive integer.

Session
eg, ne, gt, lt, ge, le
Any valid session number.

CPUTime
eq, ne, gt, lt, ge, le
Valid time in the format of hh:mm:ss. The mm and ss parameters should be between 0 and 59 and hh can be any valid unsigned numeric value.

Memusage
eg, ne, gt, lt, ge, le
Any valid integer.

Username
eq, ne
Any valid user name ([Domain\]User).

Services
eq, ne
Any valid string.


Windowtitle
eq, ne
Any valid string.


/pid ProcessID : Specifies the process ID of the process to be terminated.

/im ImageName : Specifies the image name of the process to be terminated. Use the wildcard (*) to specify all image names.

/f : Specifies that process(es) be forcefully terminated. This parameter is ignored for remote processes; all remote processes are forcefully terminated.

/t : Specifies to terminate all child processes along with the parent process, commonly known as a tree kill.

/? : Displays help at the command prompt.

Top of page

Remarks
The wildcard character (*) is accepted only when specified along with the filters.

Termination for remote processes will always be done forcefully regardless of whether the /f parameter is specified.

Supplying a computer name to the HOSTNAME filter will cause a shutdown and all processes will be stopped.

Use tasklist to determine the Process ID (PID) for the process to be terminated.

Taskkill is a replacement for the Kill tool.

Top of page

Examples
The following examples show how you can use the taskkill command:

taskkill /pid 1230 /pid 1241 /pid 1253
taskkill /f /fi "USERNAME eq NT AUTHORITY\SYSTEM" /im notepad.exe
taskkill /s srvmain /f /im notepad.exe
taskkill /s srvmain /u maindom\hiropln /p p@ssW23 /fi "IMAGENAME eq note*" /im *
taskkill /s srvmain /u maindom\hiropln /fi "USERNAME ne NT*" /im *
taskkill /f /fi "PID ge 1000" /im *

Top of page

Formatting legend
Format
Meaning

Italic
Information that the user must supply

Bold
Elements that the user must type exactly as shown

Ellipsis (...)
Parameter that can be repeated several times in a command line

Between brackets ([])
Optional items

Between braces ({}); choices separated by pipe (|). Example: {even|odd}
Set of choices from which the user must choose only one

Courier font
Code or program output