473,468 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

programmatically checking if app is running

I am programmatically starting and ending a local instance of Outlook :

//programmatically start local Outlook
System.Diagnostics.Process proc = new
System.Diagnostics.Process();
proc.StartInfo.FileName = "outlook.exe";
proc.Start();
///code
proc.Kill();

Does anybody know how I can check if it is already running before
deciding whether or not to start it?

*** Sent via Developersdex http://www.developersdex.com ***
Mar 22 '07 #1
2 4066
On Mar 22, 11:40 am, Mike P <mike.p...@gmail.comwrote:
I am programmatically starting and ending a local instance of Outlook :

//programmatically start local Outlook
System.Diagnostics.Process proc = new
System.Diagnostics.Process();
proc.StartInfo.FileName = "outlook.exe";
proc.Start();
///code
proc.Kill();

Does anybody know how I can check if it is already running before
deciding whether or not to start it?

*** Sent via Developersdexhttp://www.developersdex.com***

I had the same question and following answer solved my problem;

If you want to get a list of Processes that have a window try this
line of code.
ArrayList programlist = new ArrayList();
Process[] procList = Process.GetProcesses(userName);
for (int i = 0; i < procList.Length; i++)
{
if (procList[i].MainWindowHandle != IntPtr.Zero)
{
programlist.Add(procList[i].ProcessName + "\t" +
procList[i].MainWindowTitle);
}
}
This assumes you know the name of the logged in user (It will only get
the applications launched by the specified user, but that should be
fine for your purposes). If you don't you can obtain it through the
System.Environment class I believe.
When this code is done you will have the list of applications shown in
the Windows Task Manager. You can play around with the different
attributes like ProcessName and MainWindowTitle to find the
information you're looking for. Hope this helps. If you have any
problems with it just post back here. Good luck.
~ Justin Creasy
Thanks.

Mar 22 '07 #2
In this case, that might not be the best idea. The assumption is that
the user is actually going to DO something with Outlook. In this case, the
user is better off calling the static GetActiveObject method on the Marshal
class to get the object registered in the Running Object Table. Assuming it
returns an object, it will be the currently running instance of Outlook,
which the OP can access through Automation to make it do what he/she wants.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DBC User" <db*****@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
On Mar 22, 11:40 am, Mike P <mike.p...@gmail.comwrote:
>I am programmatically starting and ending a local instance of Outlook :

//programmatically start local Outlook
System.Diagnostics.Process proc = new
System.Diagnostics.Process();
proc.StartInfo.FileName = "outlook.exe";
proc.Start();
///code
proc.Kill();

Does anybody know how I can check if it is already running before
deciding whether or not to start it?

*** Sent via Developersdexhttp://www.developersdex.com***


I had the same question and following answer solved my problem;

If you want to get a list of Processes that have a window try this
>line of code.

>ArrayList programlist = new ArrayList();
Process[] procList = Process.GetProcesses(userName);

>for (int i = 0; i < procList.Length; i++)
{
if (procList[i].MainWindowHandle != IntPtr.Zero)
{
programlist.Add(procList[i].ProcessName + "\t" +
procList[i].MainWindowTitle);
}

>}

>This assumes you know the name of the logged in user (It will only get
the applications launched by the specified user, but that should be
fine for your purposes). If you don't you can obtain it through the
System.Environment class I believe.

>When this code is done you will have the list of applications shown in
the Windows Task Manager. You can play around with the different
attributes like ProcessName and MainWindowTitle to find the
information you're looking for. Hope this helps. If you have any
problems with it just post back here. Good luck.

>~ Justin Creasy

Thanks.

Mar 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Drydo | last post by:
In short, is it possible to swap/change the display output of a laptop to a CRT programmatically? The scenario is that we have a laptop that at the startup of a specific application would...
4
by: Whitney Kew | last post by:
Hi, Is there a programmatic way to get the "general" or "overall" version of a currently running instance of the Visual Studio .NET compiler? What I mean by "general" or "overall" version is, I...
13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
2
by: Jak Sparrow | last post by:
What are some good ways to programmatically check for software already installed on a computer? For example, to check a version of Internet Explorer, a program can check the registry for the...
6
by: Matt Frame | last post by:
I have a client that has asked us to get a digital signature certificate and start digitally signing all files we pass between each other. I have heard of the subject and know about the certs but...
32
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's...
0
by: Simon Verona | last post by:
My application autoupgrades itself by uploading an msi file from the server and then executing it, immediately terminating to let the installation script run. The problem I have is that...
14
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate...
4
by: infomage27 | last post by:
I have tried scripting this with rules and VBA, now trying with C# but still failing. (code is exploratory, so please excuse the terribleness) maybe someone here will show me the error of my...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.