Tech Support Guy banner
Status
Not open for further replies.
1 - 12 of 12 Posts

· Registered
Joined
·
160 Posts
Discussion Starter · #1 ·
Hi,

I'd like to make a program to place on my desktop so that one I open it, the program opens TWO other programs I have on my computer, and then unloads itself.

I basically want an icon on my desktop that opens two programs, and I've decided to do make it in Visual Basic.

I know a bit of Basic, but I'm not sure how to do this.

I'm assuming this is simple enough that someone could just post the code here with *insert here* or something like that for the two program file locations.

Any help is appreciated!

Thanks,
Cap'n Bob
 

· Registered
Joined
·
3,089 Posts
Create a new visual basic project (standard exe.)
Remove the Form1 that is added by default to a new project.
Add a module (not a class module.)
Insert the following code:

Code:
Private Sub Main()
   Shell "c:\windows\notepad.exe", vbNormalFocus
   Shell "c:\windows\winhelp.exe", vbNormalFocus
End Sub
You will have to go into the project properties (right click the top-most item in the project explorer) to specify that the program should start in Sub Main() rather than a form but then that shoud work.

Obviously, replace the programs that I have code above with the programs you want to execute. The parameter specified as vbNormalFocus is a startup position parameter by which you can specify that Shell'ed program is started minimized, maximixed or hidden as well as whether or not it receives the focus (active window) when loaded.

If you can't make this work, PM me with your email address and I'll mail you back the complete VB project.
 

· Registered
Joined
·
160 Posts
Discussion Starter · #3 ·
Awesome! That worked perfectly. I've had a surprising amount of trouble getting this (or a batch file) to work. Thank you very much :)

-Cap'n Bob
 

· Registered
Joined
·
3,089 Posts
Code:
#include <windows.h>

void main( void )
{
   PROCESS_INFORMATION pi;
   STARTUPINFO si;

   char p1[] = "c:\\winnt\\system32\\notepad.exe";
   char p2[] = "c:\\winnt\\system32\\calc.exe";

   memset( &si, 0x00, sizeof( STARTUPINFO         ));
   memset( &pi, 0x00, sizeof( PROCESS_INFORMATION ));

   si.cb = sizeof( STARTUPINFO );

   CreateProcess( p1, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
   CreateProcess( p2, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
}
 

· Registered
Joined
·
3,089 Posts
Use the Shell statement instead. Using the notepad example above:

Code:
Shell "c:\windows\notepad.exe c:\windows\win.ini", vbNormalFocus
The command line parameters must be in the same string with the exe name. There is no space with the Shell statement to pass parameters as a separate argument but from what this sounds like you don't need to anyway.
 

· Registered
Joined
·
3,089 Posts
The second parameter to the CreateProcess( ) API is the command line as differentiated from the executable path/file name. If the second parameter is null then the API takes the first one and uses that as the command line. Try this:

Code:
void main( void )
{
   PROCESS_INFORMATION pi;
   STARTUPINFO si;

   char p1[] = "c:\\windows\\notepad.exe c:\\windows\\win.ini"'

   memset( &si, 0x00, sizeof( STARTUPINFO         ));
   memset( &pi, 0x00, sizeof( PROCESS_INFORMATION ));

   si.cb = sizeof( STARTUPINFO );

   CreateProcess( NULL, p1, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
}
Note the reversal of the p1 and NULL in the CreateProcess( ) API. According to the MSDN documentation, if the first parameter is null then the exe name must be the first white space delimited token in the second parameter. That also means that if the path to the program contains spaces as in:

Code:
c:\\program files\\microsoft visual studio\\vc98\\bin\\dumpbin.exe
then you must use the 8.3 name in the path as in the following:

Code:
c:\\progra~1\\micros~3\\vc98\\bin\\dumpbin.exe
There can be no spaces in the path to the executable using this method. I recommend this approach over the inefficient and resource hungry system( ) calls. To obtain the correct 8.3 path name for the exe on winnt/2000/xp go to a command prompt and cd to the directory where the executable is and type command. This invokes the 16 bit dos emulator which will translate the current directory into the 8.3 compliant format for you.
 

· Registered
Joined
·
3,089 Posts
Also I just saw that the CreateProcess( ) API allows passing the exe path name (in whatever format you want) in the first parameter and the command line parameters in the second. That would probably be the easist thing so you could just ignore my previous posts. Sorry mods for so many posts in a row. I guess I'm just losing it. :D
 
1 - 12 of 12 Posts
Status
Not open for further replies.
Top