|
One solution is CreateProcess() and pass in CREATE_NO_WINDOW.
Kuphryn
|
|
|
|
|
There's a great article on this site that explains how to do this with ShellExecuteEx(). He also talks about CreateProcess as well. I've found in my particular app ShellExecuteEx() did exactly what I wanted. (I just used this in a program yesterday which is how I know the article works great!)
click here for the article
Here's the excerpt for what you are looking for:
Q: How do I start a program, and halt execution of my current program, till that program exits?
A: You start the program using ShellExecuteEx and use WaitForSingleObject on the process handle.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\MyProgram.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
...The only thing that you will have to do is where it says ShExecInfo.nShow = SW_SHOW; ... change the SW_SHOW to SW_HIDE and it'll work perfectly.
|
|
|
|
|
hi
Thank you for the reply.
I had tried the code but it seem like it cannot execute the command line tat i wanted. Because my program required me to launch this external program that require me to key in the command line on to the DOS Prompt.
My inital program
command = "jpegtran -greyscale JPEG.jpg greyscale.jpg";
system(command);
thus if I am using wat u told me, how can i execute the above command line without DOS prompt popping out.
Thank you so much
cheers
Danny Chan
|
|
|
|
|
Hey there. Here's the code snippet that I pasted in my previous post. I made some modifications to it that should suit your needs.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\jpegtran.exe";
ShExecInfo.lpParameters = "-greyscale JPEG.jpg greyscale.jpg"; // --- THIS IS YOUR PARAMS!
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
..............
Have a peek at the line
ShExecInfo.lpParameters = "-greyscale JPEG.jpg greyscale.jpg"; // --- THIS IS YOUR PARAMS!
MSDN says...
lpParameters:
Address of a null-terminated string that contains the application parameters. The parameters must be separated by spaces. If the lpFile member specifies a document file, lpParameters should be NULL.
So, using this code with
ShExecInfo.lpFile = "c:\\jpegtran.exe";
ShExecInfo.lpParameters = "-greyscale JPEG.jpg greyscale.jpg"; // --- THIS IS YOUR PARAMS!
will run the program just like:
command = "jpegtran -greyscale JPEG.jpg greyscale.jpg";
system(command);
(except by using SW_HIDE it won't show the DOS window)
Hope that helps!!
|
|
|
|
|
Hi shultas
Thank you so much for your help. But i still got a small problem to trouble u again. Hope u dont mind. Cause after inserting what you had given to me, I got this error on the <shellexecuteinfo shexecinfo="{0};"> line. This is because the shellexecute is carried out in a few case function and i think this is why it give me these errors. Hence, is it possible for u to guide me for the one last time to solve this problem. Below is the portion of my program tat I insert the codes. Thank you so much for you help. Really appreciated.
switch(*selection)
{
case'1':
//AfxMessageBox(_T("Executing Case 1"));
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\jpegtran.exe";
ShExecInfo.lpParameters = "-greyscale JPEG.jpg greyscale.jpg"; // --- THIS IS YOUR PARAMS!
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
//AfxMessageBox(_T("Opening greyscale images"));
imageFile2.Open( _T("C:\\FYP Test Folder\\best.jpg"), CFile::modeRead|CFile::typeBinary);
imageFile2.Read(image1, size.uintVal);
imageFile2.Close();
//AfxMessageBox(_T("Sending greyscale images"));
send(clientsock, (const char*) image1, size.uintVal, 0);
break;
The error message
error C2360: initialization of 'ShExecInfo' is skipped by 'case' label
cheers
Danny Chan
|
|
|
|
|
Hello Danny
I see your problem is in your case statement. Here's an article that explains pretty good what you are experiencing. Click here for article.
One way you can quickly get rid of this problem is by enclosing each of your case statements in brackets {}. case '1': { ... } case '2': { ... }
Check out that article above and let me know if you need any more help or if you got it to work
Shultas
|
|
|
|
|
Hi Shultas
It works!!! Thank you so much for your help. You are great manz!!!
cheers
Danny Chan
|
|
|
|
|
Hi Shultas
Sorry to bother you again. As the advise you gave to me work perfectly but what if i need to execute 2 different .exe in the dos prompt? What parameters do i need to insert to the shell to do it? Thank you once again. Really sorry to trouble you again.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\djpeg.exe";
ShExecInfo.lpParameters = "JPEG.jpg jpeg.ppm"; // --- THIS IS YOUR PARAMS!
ShExecInfo.lpFile = "c:\\cjpeg.exe";
ShExecInfo.lpParameters = "-smooth 50 jpeg.ppm average.jpg"; // --- This is the second program needed to execute.
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
|
|
|
|
|
Hi Danny.
That's an easy add-on!
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\djpeg.exe";
ShExecInfo.lpParameters = "JPEG.jpg jpeg.ppm"; // --- THIS IS YOUR PARAMS!
// ShExecInfo.lpFile = "c:\\cjpeg.exe";
// ShExecInfo.lpParameters = "-smooth 50 jpeg.ppm average.jpg"; // --- This is the second
// program needed to execute.
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
Lets do one at a time. So, we've got the first program to excute. Right after the WaitForSingleObject() line, put your second EXE in there. Such as this:
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\djpeg.exe";
ShExecInfo.lpParameters = "JPEG.jpg jpeg.ppm"; // --- THIS IS YOUR PARAMS!
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
// When first .EXE is done running, we'll get here. Now, we've already got most of the data
// that we need, lets just make a modification to it real quick.
ShExecInfo.lpFile = "c:\\cjpeg.exe";
ShExecInfo.lpParameters = "-smooth 50 jpeg.ppm average.jpg"; // --- This is the second
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
Bingo. Simple as that. Add those four extra lines in there. Your program will now call djpeg.exe first. Then, once that is done running, it'll call cjpeg.exe to do the rest of the work!!!!
That shall help you out!
Shultas
|
|
|
|
|
Hi Shultas
Thank you once again for you help. You are great man.;)
cheers
Danny Chan
|
|
|
|
|
NP! It's all good!
Cheers!
Shultas
|
|
|
|
|
My server application (database intensive) takes large memory.
1. I wanna confirm whether my application allocated the memory, or is the database driver is taking the memory.
2. in "TaskManager.exe" counters are as follows:
a: Memory Usage: 18,000 K
b: Virtual Memory: 10,000 K
So why is this big difference, which counter reflects the memory allocated by my code (a or b)??
Is the extra memory showed in Memory Usage counter was allocated by database driver and would be deallocated by the same driver in the end..?
|
|
|
|
|
See if this article helps.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
if the memory usage is only 18,000K I would not worry about it my db application takes 20 times that... Most people have at least 256 mb or more memory so this is not very signifigant... On my computer gator (password helper for ie) uses 33,000 K...
John
|
|
|
|
|
Don't you know gator is spyware?
One should not trust a program that does a simple task yet consumes so much memory.
|
|
|
|
|
I know but I have accounts on over 100 internet sites and it is impossible to remember all the usernames and passwords so I put up with gator. I have tryied other programs like robohelp but they suck big time...
John
|
|
|
|
|
John M. Drescher wrote:
remember all the usernames and passwords so I put up with gator
How do you know that Gator doesn't leak? It's a spyware like Trickler and I would never in my wholel ife trust a spyware! I would go for a real password reminder app instead, but that's just me...
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
Hey,
I have a question for the board. I have an application running as a Windows service. It uses printf statements to print data to the screen. However, I can't see it because no Windows command prompt is opened. Can I access another app's stout stream through another application? Thanks.
|
|
|
|
|
Normally a service does not output data to the screen. Have you tried using TextOut() instead? Otherwise, outputting to a log file of some sort is more common practice.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
I recommend using the OutputDebugString API (or MFC TRACE statements, which eventually turn into OutputDebugString calls) to output text. You can hook up a listener by attaching a debugger or a tool such as DebugView[^].
Alternatively, you may be able to see the output by giving the service Interactive logon permission. This can only be done if it's running in the SYSTEM context. I would only recommend this for debugging purposes, though - you should not consider it for a deployment.
|
|
|
|
|
Either use OutputDebugString or use one of the free logging systems from this site.
John
|
|
|
|
|
hi,
Is there any way I can create app for 98 with VC++.Net/MFC ?
I dont want to distribute the MFC70.dll.
regards
hari
|
|
|
|
|
You should be able to build your MFC6-based application using VC++ .NET 2002/03, using your old MFC lib from VC6.
Or, if you don't want to redistribute the MFC70.DLL, you could statically link... Understood that the size of your app would balloon significantly
Nick
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2003 Microsoft Corporation. All rights reserved.
|
|
|
|
|
hi,
Many thank, but..
Can you say how to use the MFC6 lib ? What should I do ?
regards
hari
|
|
|
|
|
I am not sure if this question makes sense, but I am trying to write program to send email, all the socket functions take IP address as in 155.233.55.10 and not URL address as in www.microsoft.com, wonder if there are functions that map one to the other.
Functions I am using are: connect,listen,bind,send,recv.
Thanks,
|
|
|
|