Solved

getting an app. to start another app.

Posted on 1998-12-03
11
175 Views
Last Modified: 2013-11-20
I have writtin an application that I would like to start when a particular application is started.  In other words I want to be able to start, lets say word.exe, and have my application execute at the same time.  Is this possible?
0
Comment
Question by:jamoville
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1325729
In your program you can use either WinExec() or CreateProcess() to start another application.
0
 
LVL 5

Author Comment

by:jamoville
ID: 1325730
This solution would mean the user would have to start my application first and then the other application would start.  I want the user to be able to start my application by starting a different application.  In other words, I need my application to automatically be started.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1325731
Well, this is possible by setting a shell hook using 'SetWindowsHookEx()'. When your hook proc receives 'HSHELL_WINDOWCREATED', you can check if it is e.g. 'WinWord' by using 'GetWindowText( ( HWND) wParam), ...)' (see help on 'ShellProc()' why i use 'wParam', it's a bit too much to elaborate here ;-). If so, the shell hook could start your application.
0
 
LVL 5

Author Comment

by:jamoville
ID: 1325732
Using the setwindowshookex would mean setting a global hook and unfortunatally I am unable to do that at this time.  Any other suggestions?
0
 
LVL 6

Expert Comment

by:stsanz
ID: 1325733
On Win95/Win NT 4 and over, try modifying registry key "HKEY_CLASSES_ROOT\exefile\shell\open\command" that specify what command is executed when an .EXE file is launched from the shell.

The default value is '"%1" %*' meaning the launched command is the exefile itself with all its parameters.

You can set the key value to something like 'MYLAUNCH "%1" %*'
where MYLAUNCH is a program of yours that will be executed every time a exe file is launched. MYLAUNCH will receive the exe file path as first parameter.
Then, in MYLAUNCH, you'll have the possibility to launch the exe file using WinExec or CreateProcess API.

Be careful when modifying this registry key, because it control every executable program that you will have to launch from the shell. To prevent problems, test your MYLAUNCH program first with 'batfile' key for example, that controls .BAT file launching.

Hope this helps.

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 86

Expert Comment

by:jkr
ID: 1325734
jamoville - i'm just curious, why can't you set a shell hook??
0
 
LVL 5

Author Comment

by:jamoville
ID: 1325735
Where is this registry key located.  I've not heard of this before, could you give me a little more help?

jkr- the requirements of the project I'm working on are out of my control and that's why I'm not able to create the global hook.  I'm sure that it would have worked but I think my superiors believe it would effect system resources too much.
0
 
LVL 6

Expert Comment

by:stsanz
ID: 1325736
The HKEY_CLASSES_ROOT registry key contains associations between file extensions and commands (specifies what command is executed when a file with associated extension is lauched)

Don't you know how to use REGEDIT tool ?
Execute REGEDIT (Registry editor) from WIN95/NT shell and open successively the following keys on the left part of the Registry editor window :
HKEY_CLASSES_ROOT, exefile, shell, open, command
(HKEY_CLASSES_ROOT contains a great amount of ".xxx" keys. "exefile" is located after those ones in ASCII order)
Then, on the right part of the Registry editor window, you can modify "(Default)" key by double-clicking it.

On what system are you working :
Win 3.x ? Win 95 ? NT 3.51 ? NT 4 ?

Once again, be careful when modifying registry keys. As I last wrote, you should first test your program by modifying "batfile" key instead of "exefile" and try lauching a .BAT file.

Here is a small code piece that can be used for a MYLAUNCH program, as I described earlier :

#include  <windows.h>
int  WINAPI  WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
      MessageBox(NULL,lpCmdLine,"MYLAUNCH parameters",MB_OK) ;
      WinExec(lpCmdLine,SW_SHOWDEFAULT) ;
      return 0 ;
}

- Compile your program with name MYLAUNCH.EXE in, for example, C:\BIN\ directory
- Modify "batfile\(Default)" key value to set it to 'C:\BIN\MYLAUNCH "%1" %*'
- Run a .BAT file (it must exist)

--> MYLAUNCH is first executed, displays the .BAT file name you typed in in a message box, and the .BAT file is launched.


0
 
LVL 5

Author Comment

by:jamoville
ID: 1325737
This answer is great, but I've been told that I can't change the registry for the application.  Unfortunetly I don't know why.  Is there a different solution.  If not, I will give you the point anyway.
0
 
LVL 6

Accepted Solution

by:
stsanz earned 50 total points
ID: 1325738
Well, you're not allowed to do much !
Instead, you can possibly move the exe file of the application you want to execute (let's say '..\Program Files\Microsoft Office\Office\WINWORD.EXE') to a directory that is not in the PATH environment variable. Then replace '..\Program Files\Microsoft Office\Office\WINWORD.EXE'
by your own WINWORD.EXE program, which does its own stuff and then launch the real WINWORD.EXE (you can use MYLAUNCH example for this purpose).

Thus, any WINWORD executed from the shell will launch your own WINWORD.EXE

I haven't tested this solution, but you should find your way based upon this idea.
Hope this helps !

0
 
LVL 5

Author Comment

by:jamoville
ID: 1325739
I think your answers a great and I know the registry solution would have work.  You right I'm not allowed to do much.  O well, ya gotta listen to the boss I guess.  Thanks for your input and I'll try you other solution.  It sound logical.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now