Archived

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

Oranda

How do I launch another program internally from C?

Recommended Posts

Oranda    122
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 this post


Link to post
Share on other sites
pirate_dau    151

  
#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 this post


Link to post
Share on other sites
LessBread    1415
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 this post


Link to post
Share on other sites
Flikm    122
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 this post


Link to post
Share on other sites
Oranda    122
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 this post


Link to post
Share on other sites
a person    118
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 this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
pirate_dau    151
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

Share this post


Link to post
Share on other sites
Oranda    122
We''ve been using Novell to remotely apply those policy settings for a long time now. They work okay, but it still isn''t perfect. And there is of course the whole "fun factor" here .

But the really big reason we want to do this is it gives the uses nice big buttons with pictures and simple labels like "The Internet". Nice and easy.

Share this post


Link to post
Share on other sites