Visual Basic- Help With Very Simple Program

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Capnbob

Thread Starter
Joined
Feb 17, 2004
Messages
160
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
 
Joined
Oct 12, 2003
Messages
3,015
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.
 

Capnbob

Thread Starter
Joined
Feb 17, 2004
Messages
160
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
 
Joined
Mar 28, 2004
Messages
51
I don't mean to butt in, Capnbob, but would this be as easy with C++? (I haven't purchased VB yet...) :(
 
Joined
Oct 12, 2003
Messages
3,015
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 );
}
 
Joined
Mar 28, 2004
Messages
51
Thanks! How would I pass command-line options to it? For example, for an image program, paramaters would include the file to open and resize paramaters.
 
Joined
Mar 28, 2004
Messages
51
Nevermind-- I think I can just use the system() command:

system("c:\programpath /file=thefile /otherparamaters=stuff");
 
Joined
Oct 12, 2003
Messages
3,015
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.
 
Joined
Oct 12, 2003
Messages
3,015
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.
 
Joined
Oct 12, 2003
Messages
3,015
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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top