How do I launch another program internally from C?

Started by
9 comments, last by Oranda 21 years, 11 months ago
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.
Advertisement

  #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
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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" );
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 .
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
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
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).
In that case I think you''ll find this link invaluable: Wayne''s NT Resources for Administrators and Users
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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.
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

This topic is closed to new replies.

Advertisement