Page 1 of 1

[Solved] How to kill proces

PostPosted: Sun May 05, 2019 5:50 pm
by lodovi
Hi, I'd like to use a macro to stop running an acrobat reader before creating a pdf.
I'm trying something like that :
oSys = CreateUnoService("com.sun.star.system.SystemShellExecute")
oSys.execute("C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe","",0)
oSys.execute("C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe", "kill",1)

or like this
shell("pkill C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe")

Or close the open file directly
address = ConvertToUrl(sPATH)
shell("pkill" & address)

The problem is that I want to overwrite the open PDF file, so I must close it first, otherwise the program ends with an error.

I don't know Shell at all, I'm just trying.
Can anyone help? Thanks

Re: How to kill proces

PostPosted: Mon May 06, 2019 9:22 am
by Bidouille
This question should be posted in macro area.

What is pkill? You want run a Unix command under Windows.
Remember that this kind of tool wait a PID and not a pathname.

Re: How to kill proces

PostPosted: Mon May 06, 2019 9:33 am
by lodovi
How can I get PID?

Re: How to kill proces

PostPosted: Mon May 06, 2019 12:01 pm
by JeJe
There's a couple of suggestions here:

https://stackoverflow.com/questions/183 ... n-from-vb6

http://www.vbforums.com/showthread.php? ... pplication

(vb6 code can often work or be adapted to OO so do a search for VB6 and what you want and you may get a solution)

Re: How to kill proces

PostPosted: Mon May 06, 2019 1:30 pm
by hubert lambert
Hi,

This single line shoud work ("shell" is a basic runtime command):
Code: Select all   Expand viewCollapse view
    shell("taskkill", 0, "/f /im AcroRd32.exe", True)

More info on "taskkill": https://docs.microsoft.com/en-us/window ... s/taskkill.

Regards.

Re: How to kill proces

PostPosted: Mon May 06, 2019 7:28 pm
by lodovi
Super, super, super :) It works absolutly great. Thank you very much everybody and especially hubert lambert