#### Archived

This topic is now archived and is closed to further replies.

# How do I launch another program internally from C?

This topic is 5898 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m writing a shell replacement for Windows, and I need to be able to launch a program when somebody clicks on one of my buttons. I''ve never needed to do this before, and I was wondering if somebody could tell me how to do it from C++ and VB. Speed is not a requirement, so even a simple funtion that just takes the path as an argument would be ideal. Thanks.

##### Share on other sites

  #define WIN32_LEAN_AND_MEAN#include <process.h>#include <windows.h>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmd) {	_execlp("javaw", "javaw", "-jar", "cdt.jar", 0);	return 0;}

Help any? This particular example is spawning an executable Java jarfile, but you can use this for anything *shrug*

-pirate_dau

##### Share on other sites
From the C library there''s "system". From the Win32 API there''s CreateProcess and ShellExecute. If you haven''t done so already, you might want to take a look at LiteStep among other already written shell replacements, also maybe take a look at shellcity.com et al.

##### Share on other sites
system( "myprog.exe" );
OR
int _spawnl( int mode, const char *cmdname, const char *arg0, const char *arg1, ... const char *argn, NULL );

spawnl( P_WAIT, "myprog.exe", "firstarg", "secondarg", "onandon" );

##### Share on other sites
Thanks guys, that was exactly what I needed .

As for Litestep, I need a very specific shell. I work at a school, and I''m coding a shell to prevent the students from accessing any settings that they shouldn''t be playing with (like proxy settings and stuff). Think of two or three floating Aquabars. Very simple and intuitive, and extremely secure .

##### Share on other sites
If your LAN is NT based you can implement NT security policies that restrict usersfrom making various changes to settings etc. A Windows 2000 environment gives you even more control. Still, writing your own Windows shell is fun

Dire Wolf
www.digitalfiends.com

##### Share on other sites
just make sure your shell does not allow running of arbitray programs and does not use ie for its explorer unless you cripple it by checking the url before fetching it. IE allows you to run local files, by just typing it in the url box. netscape, opera and other browsers may also have this feature.

also as a precauntionary you should either disallow floppy booting or remove floppy drives. a simple reboot with a dos/win boot disk can allow the student to change the shell settings back to the default rather easily. granted if they are that clever you may not care. look for security apps that can lock windows down at a lower level then a shell replacment can. they may be out of your price range depending of the school budget and number of pcs, but its another option (especially since many also offer file security as well).

##### Share on other sites
I''m not sure where the _execlp answer came from, but I''ve always used CreateProcess(), et al. MSDN will have the rest of the information.

##### Share on other sites
Ya got me. It''s in my program, but it was done by another programmer. I just knew that it was in my code, and that it did what was asked in the original question. Sounds like other people came up with some pretty good suggestions, though.

-pirate_dau

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631435
• Total Posts
3000056
×