473,785 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running another exec file

I have a C# programme that needs to run some of Windows executable
files. I first need to check if that programme is already running, and
if it is, simply bring the window to the front. How can I search for a
Window handle of an execute file?

Nov 16 '05 #1
3 4187
You'd have to resort to Win32 API calls.

At the least, you need to know your "other" application's window title. If
you do, you can do a FindWindow (...) to get a handle to the window and
SetForegroundWi ndow () to bring it to front.

However, this method is in no way fool-proof. Someone else can come by and
set their window's title to match your "other" app's window title and you'll
be stuck forever not able to execute your "other" app.

Or, your "other" app might be in starting up phase and its window has not
been created yet. FindWindow will fail and your app will happily go ahead
and launch it again; you'll end up with two instances.

One clean way to solve this problem is make your "other" app inherently
singleton. You can use named kernel objects to solve the problem (mutex,
event, etc).

HTH

-vJ

"No One" <no***@yahoo.co m> wrote in message
news:40******** *******@yahoo.c om...
I have a C# programme that needs to run some of Windows executable
files. I first need to check if that programme is already running, and
if it is, simply bring the window to the front. How can I search for a
Window handle of an execute file?

Nov 16 '05 #2
Check out System.Diagnost ics.Process. In particular, the GetProcessesByN ame
method and the MainWindowHandl e property.
"No One" <no***@yahoo.co m> wrote in message
news:40******** *******@yahoo.c om...
I have a C# programme that needs to run some of Windows executable
files. I first need to check if that programme is already running, and
if it is, simply bring the window to the front. How can I search for a
Window handle of an execute file?

Nov 16 '05 #3
General approach is: In application we should create any named kernel object
(for example Mutex),
then we can access to it from any windows apps by name. Moreover we can
define is object created early or in current function.
And if it is new instance of Mutex, so application already running and vice
versa.
In .NET Win32 Mutex represented by System.Threadin g.Mutex namespace.
Example:

class MyApplication
{
public static void Main()
{
if ( InstanceExists( ) )
{
return;
}
Console.WriteLi ne( "Applicatio n is running: Press enter to exit" );
Console.ReadLin e();
}

static Mutex mutex;
static bool InstanceExists( )
{
bool createdNew;
mutex = new Mutex( false, "My Mutex Name", out createdNew );
return !createdNew;
}
}

"No One" <no***@yahoo.co m> wrote in message
news:40******** *******@yahoo.c om...
I have a C# programme that needs to run some of Windows executable
files. I first need to check if that programme is already running, and
if it is, simply bring the window to the front. How can I search for a
Window handle of an execute file?

Nov 16 '05 #4

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

Similar topics

8
3323
by: Sticks | last post by:
ok... im not quite sure how to describe my problem. i have a php script that runs through my entire php site and writes the resulting output to html files. this is necessary as the nature of the hosting available to me for this particular page prohibits me from using php/mysql as i would like. my script works simply by using output buffers and an include the relevant section of code is as follows: ob_start();
0
1444
by: LRW | last post by:
I'm using a PHP script to run some command line...commands, and they seem to half work. Here's what I have: <?php $mog = escapeshellcmd("/usr/bin/mogrify -size 180x180 -colorspace RGB +profile \"*\" /usr/shipthumbs/*.tif"); $mont = escapeshellcmd("/usr/bin/montage -tile 4x4 -colorspace RGB -label \"%f\" -resize 180x180 -geometry 180x180+0+0 -gravity South /usr/shipthumbs/*.* /usr/shipthumbs/montage.png");
0
2758
by: Steve Thorpe | last post by:
Hi I am trying to write a report that calculates the average number of sales over 7, 14, 31 and 365 days for each hourly period of the day. the problem is it takes over 4 minutes to run. e.g. Average Xactions per Hour 7 Days 14 Days 31 Days 365 Days 00:00 - 01:00 1,141.6 579.2 261.6 28.8
1
3710
by: Steve Thorpe | last post by:
Hi I am trying to write a report that calculates the average number of sales over 7, 14, 31 and 365 days for each hourly period of the day. the problem is it takes over 4 minutes to run. e.g. Average Xactions per Hour 7 Days 14 Days 31 Days 365 Days 00:00 - 01:00 1,141.6 579.2 261.6 28.8
8
3040
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to what I really should do. I've had a look through Programming Python and the Python Cookbook, which have given me ideas, but nothing has gelled yet, so I thought I'd put the question to the community. But first, let me be a little more detailed...
4
3759
by: benwylie | last post by:
I am running IIS 6.0 on Windows 2003. I would like to be able to run a perl script from a web page and include the output. I have tried doing it with an ssi: <form action='docsearch.shtml' method='get'> <!--#exec cgi="/cgi-bin/docsearch.pl--> </form> This correctly ran the script, but it was unable to include the
21
7864
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
1
7594
Nepomuk
by: Nepomuk | last post by:
Hi! I'm trying to run an external Program with Process p = Runtime.getRuntime().exec("/bin/sh -c \"/bin/gzip -c /home/user/workspace/TarGz/pics.tar > pics.tar.gz\""); CleanStream cleanError = new CleanStream(p.getErrorStream(), "ERROR"); CleanStream cleanOutput = new CleanStream(p.getInputStream(), "OUTPUT"); clearError.start(); clearOutput.start(); p.waitFor(); under Linux.
7
2196
by: alito | last post by:
Hi all, I am new to using packages to group my modules. I can't figure out how to run a module that uses relative imports without writing a wrapper that imports that module. Everything I try it complains that I am attempting a relative import in a non-package. eg ~/python/testpackage$ ls config.py importer.py __init__.py
3
7016
by: Shayco | last post by:
hey, in my code i'm using Runtime.getRuntime().exec() in order to run a .bat file that calls another java program (they communicate with each other using RMI). when i call: Process process = Runtime.getRuntime().exec("cmd /c start C:\\MyFolder\\JavaApp.bat"); the seperate process runs perfectly, but when i add a space to the path: Process process = Runtime.getRuntime().exec("cmd /c start \"C:\\My Folder\\JavaApp.bat\""); then the java.exe...
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4053
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 we have to send another system
3
2880
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.