Page 1 of 1 1
Topic Options
#193668 - 2009-05-05 08:49 AM Check if process is running and activate
Laggetjeuh Offline
Just in Town

Registered: 2009-05-05
Posts: 4
Loc: Netherlands
Hi,

This is my first post here, I've used the search function but couldn't find what I was looking for...

So here's my problem/request:
I've created an application using kixscript and kixforms.

When this application is launched it starts another executable (program2.exe). This program2.exe is started minimized by using the "start /MIN program2.exe" command.

I created a button that launches program2.exe when it's clicked.
However when someone clicks this button it launches another instance of program2.exe, instead of maximizing it from the taskbar.

So I created some sort of workaround that kills program2.exe using the StopProc() process (found here on kixtart.org) and then launches it again.

Unfortunately this is not the way it should work, program2.exe should keep on running and maximize when someone clicks the button in the application.
It should not be running twice either.

So I was wondering if there's a way to do the following:

- Check if program2.exe is running
- Maximize/activate program2.exe if it is running

If this would exist (for example functions called ProcRunning and ProcActivate) I can then put this function under the button like:

If ProcRunning(program2.exe)
ProcActivate(program2.exe)
Else
Run program2.exe
EndIf

I hope someone can help me out.
Thanks in advance!

Regards,
Jeroen


Edited by Laggetjeuh (2009-05-05 08:50 AM)
Edit Reason: typos

Top
#193669 - 2009-05-05 09:16 AM Re: Check if process is running and activate [Re: Laggetjeuh]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
First a small comment.
This post does not belong in this section. It should be in basic or advanced scripting. Can a MOD please move it?

You can control an application (minimize, maximize, restore and close) with the code below.

 Code:
Break on

$app = "Untitled - Notepad"
$action = 2
$rc = AppWindow($app, $action)

Function AppWindow($app, $action)
	Dim $rc
	Select
			;minimize alt + space + n
		Case $action = 1
			$keys = "~n"
			;maximize alt + space + x
		Case $action = 2
			$keys = "~x"
			;restore alt + space + r
		Case $action = 3
			$keys = "~r"
			;close alt + F4
		Case $action = 4
			$keys = "~{F4}"
	EndSelect
	
	If SetFocus($app) = 0
		$rc = SendKeys($keys)
	Else
		Exit @error
	EndIf
EndFunction


Edited by Mart (2009-05-05 09:18 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193674 - 2009-05-05 10:53 AM Re: Check if process is running and activate [Re: Mart]
Laggetjeuh Offline
Just in Town

Registered: 2009-05-05
Posts: 4
Loc: Netherlands
oh sry, wasn't sure whether to post it in basic or advanced scripting (don't consider myself an advanced scripter yet), but I thought I posted this in basic scripting..

I'll test the function right away!
Thanks!

Top
#193676 - 2009-05-05 11:00 AM Re: Check if process is running and activate [Re: Laggetjeuh]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
That’s OK. A mod moved it already.

If you have any questions then please post them.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193678 - 2009-05-05 11:13 AM Re: Check if process is running and activate [Re: Mart]
Laggetjeuh Offline
Just in Town

Registered: 2009-05-05
Posts: 4
Loc: Netherlands
The function seems to work, though not for my application \:\(
This is not the functions fault, but the application's because the application doesn't have a maximize/minimize button or function.

(so starting it with the /MIN parameter was already a cheap way of minimizing an unminimizable application, rightclicking the application in the taskbar also doesn't show a maximize option)

I'll see if I can get the creator of the application to include these options so I can use the function to maximize it.

Is there also a function to check if a process is running?
This would at least help me out for now so I can skip starting program2.exe if it's already running.

Thanks in advance!

Jeroen

Top
#193680 - 2009-05-05 11:21 AM Re: Check if process is running and activate [Re: Laggetjeuh]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Have a look at the EnumProcces() UDF in the UDF section. This UDF will let you check if a process is running and if needed kill it.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193682 - 2009-05-05 12:56 PM Re: Check if process is running and activate [Re: Mart]
Laggetjeuh Offline
Just in Town

Registered: 2009-05-05
Posts: 4
Loc: Netherlands
thanks, that did the trick so far!
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 515 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.042 seconds in which 0.019 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org