Perform an action when a program starts - windows

Let's say I wanted to run a batch file when a specific EXE is started. Are there any hooks for this in the Win32 API?
I'm using VCL with Delphi, but general info on this would be nice as well.
The program is supposed to run in the background, and, when the user starts an application, the program detects this, checks whether the application matches the criteria and runs the associated batch file if so.

Have you tried to use the Create Process Function of Delphi?
Here is a small link that it can guide you for the process:
http://snipplr.com/view/59064/using-createprocess-to-execute-programs/

Related

Detect a running program and launch a different one

I have a scenario in Windoze where I'd like to monitor for program A to be running before launching program B. I've google'd for related topics and all I've come across are posts for using batch files to kick off multiple apps in sequence (with/out delays). The use case I'm facing is that the user can download a file which causes program A to launch, so I don't always know when A will be started (i.e. can't just make a batch file with a shortcut on the desktop for the user).
I'd like to find a somewhat native solution that would routinely scan for program A running (could simply set up a Task that repeats) and then kicks off program B.
If a more complex method needs to be employed, so be it, but I'd prefer a minimally-invasive solution... simple language, simple development environment, etc.

Is it possible to run a batch file when a program is launched?

I have a batch file that toggles aero. Is there a way that when you open a certain program the batch file will run when it is launched and run again when the program is closed?
Well yes, but on the Properties for the program you can tick a checkbox to do this on the compatability tab.
Find out info on what the browser is doing. Sart your program and then use Task manager to find your game (it is a real game and not some jscript web thing?).
Compatability layers are scritable.
See http://support.microsoft.com/kb/286705
set __compatlayer=256Color (note wrong spelling)
Running a program will have same problem as setting compatability. You have to find something to run it on.
Windows can start a debugger automatically when a program is started. You can substitute any program that can start a program (as a batch can) for the debugger.
You can also run a script that triggers on program start. Task Scheduler can run tasks when certain events occur.
But you have to know what exact object to trap. Use task manager in the first instance.

Figuring out how one program launches another program on Windows

I have a Windows program -- a vendor-provided benchmark utility -- that launches an existing game on my system using a set of launch options. I'd like to figure out what those launch options are. Is there any way to detect how the benchmark utility is launching the game?
More generally, is there some tool I can use to detect when and how one process launches another process on Windows?
As I was faced with the same problem, I figured out a simple, yet for my needs great solution.
I exchanged the called program with a simple custom-written c-program which prints all passed arguments into a logfile.

Launching an application from another process

We have an application that we have built as a bundle and we want to launch it from another process.
How should we do it?
From what I understand we can use openUrls(), openFile() or execve()
but I don't know which one better suits us.
Thanks
Since you're talking about an application, you don't want to go through the file association mechanisms. They're for opening documents, images etc. with an appropriate application. Since you don't seem to be sure what to ask, I'd say keep it simple:
The exec* family launches an executable directly. But note that it replaces the launching process with the launched application. Your launcher will stop executing at that point. If you want the launcher to continue to run, you want to use something that launches a subprocess. The low-level way is fork/vfork followed by exec, but it's far simpler to launch your app with system, which takes care of all that behind the scenes. (Assuming there are no security concerns about users on the other side of the world injecting execution paths).
If the launcher does not terminate as soon as it launches your app, you'll want to think about whether it "blocks" until the launched application terminates, or whether it launches the app asynchronously-- so that they then run in parallel. The launcher might also "wait" for the return value of the app, to check whether it succeeded and maybe do something afterwards. There are ways to do all that, but since we don't know what you need, I won't go into details.
In short: If the only job of your launcher is to start your app, use execl. If your launcher needs to do more, use system. If neither one quite fits your needs, you'll need to provide more information-- starting with the language your launcher is written in.
PS. Both of these have the advantage of generality and portability. They work for GUI and commandline applications, and they'll work on any Unix-like system, and to some extent on Windows. There's no need to lock yourself into Cocoa for something so simple.
If you're using Cocoa, you can use NSWorkspace's -launchApplication:.
From OSX documentation on NSWorkspaces:
openFile: Opens the specified file specified using the default application associated with its type.
openURL: Opens the location at the specified URL.
With url you can open also file on ftp, or http for example.

Application to watch what an executable does?

I need to find out exactly what files/directories a Lua program uses so I can try to only pack what it needs into a ZIP file, and come up with a simple way to deploy this script.
I used SysInternals' Process Monitor, but I'm surprised by the small amount of information it returned while it watched the program (For Lua users out there, it's wsapi.exe, which is the launcher for the light-weight Xavante web server).
Does someone know of a good Windows application that can completely monitor what a program does, eg. something like a live version of the venerable PCMag's InCtrl5.
Thank you.
Process monitor will catch everything. If it's not catching the action then it must be happening in a different process. Try filtering based on the files you expect to be used rather than the process you expect it to happen in.

Resources