Solved

getting an app. to start another app.

Posted on 1998-12-03
11
178 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 76
Generic progress indicator 6 117
How do you programatically show and hide the Windows 10 On-Screen-Keyboard? 3 675
lucky13 challenge 11 146
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

809 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