|
-
August 9th, 2001, 04:16 PM
#1
Dynamically opening an external program
Hello everyone,
How would I dynamically open a program without knowing the path name?
-
August 9th, 2001, 04:18 PM
#2
Re: Dynamically opening an external program
Please, be more specific (some kind of example would be great)
Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
[email protected] | ICQ:57404554 | http://soukhov.com
Member of Russian Software Developer Network http://rsdn.ru
-
August 9th, 2001, 04:35 PM
#3
Re: Dynamically opening an external program
use the function:
WinExec("someapp.exe", SW_SHOW);
if you dont specify a pathname it will search directories in a specific order. Check out WinExec in the index in MSDN.
Hope this helps
-
August 9th, 2001, 04:49 PM
#4
Re: Dynamically opening an external program
yes (it's 'bout "confused even more") =)))
anyway - you should provide a full path to you executableProgramm.exe if this executable not in:
system catalogue, current catalogue, in path .... and use CreateProcess or ShellExecute to run a programm ...
Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
[email protected] | ICQ:57404554 | http://soukhov.com
Member of Russian Software Developer Network http://rsdn.ru
-
August 10th, 2001, 12:36 PM
#5
Converting DOS command line to Windows-based
Hello everyone,
I am trying to convert a command line that is in a DOS format into one that will run in Windows. It is still dynamically allocated, but in have parameters to pass in to the program call. The DOS command is as follows:
SOME_EXECUTABLE MY_FILE -p SOME_PARAM -a ANOTHER_PARAM ...
Any suggestions, clues, sites to look at?
TIA
-
August 10th, 2001, 12:51 PM
#6
Re: Converting DOS command line to Windows-based
system("SOME_EXECUTABLE MY_FILE -p SOME_PARAM -a ANOTHER_PARAM ...");
I don't know if you need the ful path for the executable or not.
-
August 10th, 2001, 01:05 PM
#7
Re: Dynamically opening an external program
SHELLEXECUTEINFO ShExecInfo;
HINSTANCE hInst = NULL;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = NULL;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "Open";
ShExecInfo.lpFile = Myprogram.exe; // with full path
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_MAXIMIZE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
Best Regards
Agha Shujaa Khan
-
August 10th, 2001, 01:46 PM
#8
Re: Dynamically opening an external program
-
August 10th, 2001, 02:03 PM
#9
Re: Converting DOS command line to Windows-based
You don't need the full path as long as your application you want to start is within the search path which is set in your environment...
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
-
August 10th, 2001, 02:08 PM
#10
Re: Converting DOS command line to Windows-based
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
// Zero structures
memset(&StartupInfo, 0, sizeof(StartupInfo));
memset(&ProcessInfo, 0, sizeof(ProcessInfo));
// Set structure size
StartupInfo.cb = sizeof(StartupInfo);
// Start other application
CreateProcess("SOME_EXECUTABLE",
"MY_FILE -p SOME_PARAM -a ANOTHER_PARAM",
NULL,
NULL,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
NULL,
NULL,
&StartupInfo,
&ProcessInfo);
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
-
August 11th, 2001, 10:53 AM
#11
Re: Dynamically opening an external program
SHELLEXECUTEINFO ShExecInfo;
HINSTANCE hInst = NULL;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = NULL;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "Open";
ShExecInfo.lpFile = Myprogram.exe; // with full path
ShExecInfo.lpParameters = “MY_FILE -p SOME_PARAM -a ANOTHER_PARAM ...”;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_MAXIMIZE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
It is extremely simple thing to execute external programs with any number of parameters.
-
August 11th, 2001, 03:48 PM
#12
Re: Dynamically opening an external program
I am sorry if I have insulted your intelligence in any way, but I didn't understand the first post, which is why I asked what it did. Assuming this is an "extremely simple thing to execute," I would really appreciate some type of comment to explain this marvelous piece of code that you have provided for me. Thank you again for responding.
-
August 11th, 2001, 05:35 PM
#13
Re: Dynamically opening an external program
Hi,
His code is one way to start another application.
SHELLEXECUTEINFO ShExecInfo;
HINSTANCE hInst = NULL;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); // Size of this structure in bytes
ShExecInfo.fMask = NULL; // Array of flags that indicate the content and validity
// of the other structure members
ShExecInfo.hwnd = NULL; // Window handle to any message boxes that the system may
// produce while executing this function
ShExecInfo.lpVerb = "Open"; // Specifies an action for the application to perform
ShExecInfo.lpFile = "c:\\notepad.exe"; // Application to be started (with complete path)
ShExecInfo.lpParameters = "MY_FILE -p SOME_PARAM -a ANOTHER_PARAM"; // Specifies the command line arguments for the application
// to be started
ShExecInfo.lpDirectory = NULL; // Specifies the working directory for the application
// to be started
ShExecInfo.nShow = SW_MAXIMIZE; // Specifies how the application is to be shown when
// it is opened
ShExecInfo.hInstApp = hInst; // Receives a value greater than 32 if successful, or an error
// value that is less than or equal to 32 otherwise
There are some optional members of this structure (like process handle, icon handle, hot ke etc.) which you can also set before passing this structure to 'ShellExecuteEx()'. See MSDN (http://msdn.microsoft.com) for further information. Hope this helps.
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
-
August 11th, 2001, 11:00 PM
#14
Re: Dynamically opening an external program
This is a console application (ExeToPad , I meant Executable to notepad), which I complied and tested and works ok. I demonstrated with this program that how you can open notepad with this program. As you might know that notepad accept line arguments, a file name which you like to open. You might not have that file, but notepad will accepts mytest.txt file name as argument and will give you an error message “can not find mytexr.txt file. Do you want to create that file?
Here is the whole program.
#include "stdafx.h"
#include <windows.h>
int main(int argc, char* argv[])
{
SHELLEXECUTEINFO ShExecInfo;
HINSTANCE hInst = NULL;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = NULL;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "notepad.exe";
ShExecInfo.lpParameters = "mytext.txt";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_MAXIMIZE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|