473,486 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Terminate Adobe Acrobat in c#

3 New Member
I am looping through and printing multiple pdf files. After I'm done printing, Adobe Acrobat is still running. I would like to find a way to shut it down. Here is the code within the loop:

Process p = new Process();
p.StartInfo.FileName = fileName;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Verb = "print";
p.Start();
p.Dispose();

I have tried to use:
p.Start();
p.WaitForExit(10000);
p.Kill();

This will kill acrobat, but it does so before all printing is complete. Is there a way to find any instance of Acrobat running and terminate it at any point I wish.
I have looked at MSDN and found an example to do this with notepad using Process.GetProcessById and thought of using Process.GetProcessByName("Acrobat.exe") but this does not return any process. Any Ideas?
May 17 '07 #1
3 7450
TRScheel
638 Recognized Expert Contributor
I am looping through and printing multiple pdf files. After I'm done printing, Adobe Acrobat is still running. I would like to find a way to shut it down. Here is the code within the loop:

Process p = new Process();
p.StartInfo.FileName = fileName;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Verb = "print";
p.Start();
p.Dispose();

I have tried to use:
p.Start();
p.WaitForExit(10000);
p.Kill();

This will kill acrobat, but it does so before all printing is complete. Is there a way to find any instance of Acrobat running and terminate it at any point I wish.
I have looked at MSDN and found an example to do this with notepad using Process.GetProcessById and thought of using Process.GetProcessByName("Acrobat.exe") but this does not return any process. Any Ideas?

Throw it into a console app, and loop through the Process.Threads. Watch their thread states, and find what changes after printing is done. Then create a watch for that, and kill it when that happens.
May 17 '07 #2
derndeh
3 New Member
Throw it into a console app, and loop through the Process.Threads. Watch their thread states, and find what changes after printing is done. Then create a watch for that, and kill it when that happens.
I've tried doing this. Maybe it is because of my lack of understanding on how to do this properly(very likely), but I wasn't able to find anything that would help me find the right time to kill the process. I have however figured out how using [DllImport("USER32.DLL")] I could find the running instance of Acrobat and use Sendkeys to send it Alt+F4. Thanks for the suggestion though.
May 21 '07 #3
TRScheel
638 Recognized Expert Contributor
I've tried doing this. Maybe it is because of my lack of understanding on how to do this properly(very likely), but I wasn't able to find anything that would help me find the right time to kill the process. I have however figured out how using [DllImport("USER32.DLL")] I could find the running instance of Acrobat and use Sendkeys to send it Alt+F4. Thanks for the suggestion though.

this should work:


Expand|Select|Wrap|Line Numbers
  1.        Process process = new Process();
  2.             process.StartInfo.FileName = filename;
  3.             process.StartInfo.CreateNoWindow = true;
  4.             process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  5.             process.StartInfo.Verb = "Print";
  6.  
  7.             process.Start();
  8.  
  9.             bool IsDone = false;
  10.             while (!IsDone && !process.HasExited)
  11.             {
  12.                 IsDone = true;
  13.                 process.Refresh();
  14.                 if (!process.HasExited)
  15.                 {
  16.                     foreach (ProcessThread thread in process.Threads)
  17.                     {
  18.                         if (thread.ThreadState != System.Diagnostics.ThreadState.Terminated)
  19.                             IsDone = false;
  20.                     }
  21.                 }
  22.             }
  23.  
  24.             if (!process.HasExited)
  25.             {
  26.                 process.WaitForExit(1000);
  27.                 process.Kill();
  28.             }
  29.             process.Dispose();
May 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4452
by: Andy W | last post by:
I'm wanting to automate Adove Acrobat Reader using Com thru Python and win32com, but i can't find any documentation for the Adobe stuff? Has anyone done anything with Acrobat COM ? I've searched...
3
1998
by: Hank Reed | last post by:
I have been using the ShellExecute command for about a year to print out a list of PDF files. It's a great capability. Of course, the documents are actually printed by the Adobe application. We...
1
3902
by: JohnC | last post by:
I have this exact same scenario. It is new and seems to be related to when we installed Adobe 7.0 Standard/Professional. We have an MDB on a LAN file server. Using Access 2K and Windows 2K. ...
6
5251
by: jdph40 | last post by:
We recently had to upgrade the computers in our company. Now our office's website on our company intranet no longer recognizes reports saved in snapshot format. We get an error message that the...
3
6584
by: moroni | last post by:
No problem 2 set Access up to get address data from tblClients then to use a form as a letterhead and to keyboard in the letter content then save the letter to a tblCorrespondence Get a scanner....
3
8207
by: frenchy | last post by:
I am getting this error in Adobe after struggling with a 'submit' button on an acrobat form that is in production and all the other appdev people in the office are NOT having a problem with. It...
1
1827
by: Stinky Pete | last post by:
Hi, With thanx to the group and suggestions to review other news sites, I've got some code that allows me to open Adobe from Access. As I am new at this, I still need some help though. The...
11
2047
by: saintor1 | last post by:
I can't believe how much time I spent on this. I finally found the cause and it was Adobe 7.0 Professional. What happened was that a database could be opened once, but the subsequent users got...
2
8071
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a server 2008 IIS 7.0 with indexing service installed. I have created the catalog and have a test page using these posts:...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.