Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question regarding use of ShellExecute 1

Status
Not open for further replies.

sdc

Programmer
Nov 28, 2000
4
US
I am trying to use ShellExecute to launch an application with an input file. What I want to happen is the equivalent of typing &quot;C:\application.exe <input.txt&quot; on the command line. I have tried the following:

ShellExecute(m_hWnd, &quot;open&quot;, &quot;C:\\application.exe&quot;, &quot;<input.txt&quot;, NULL, SW_SHOWNORMAL);

Can anyone point out what I am doing wrong or another way to accomplish what I want to do?

Thanks
Scott


 
hi,sdc:
I understand what you want to do.
I implemented it using &quot;CreateProcess&quot;.
Hope it may help you.

HANDLE hReadFile;
STARTUPINFO si;

hReadFile=CreateFile(&quot;c:\\input.txt&quot;,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
memset(&amp;si,0,sizeof(STARTUPINFO));
si.cb=sizeof(STARTUPINFO);
si.dwFlags=STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.wShowWindow=SW_SHOWDEFAULT;
si.hStdInput=hReadFile;
PROCESS_INFORMATION pi;

CreateProcess(&quot;d:\\application.exe&quot;,
NULL,
NULL,
NULL,
TRUE,
CREATE_DEFAULT_ERROR_MODE,
NULL,
NULL,
&amp;si,
&amp;pi);
//remember to close owned handles
CloseHandle(pi.hThread);

//Wait long enough for the new created process to end
WaitForSingleObject(pi.hProcess, 8000);

//Remember to close the handle of the file
CloseHandle(hReadFile);

gzjungle
 
Actually SDC, what you are probably looking for is:
********

ShellExecute(NULL, &quot;open&quot;, &quot;C:\\application.exe&quot;, &quot;<input.txt&quot;, NULL, SW_SHOWNORMAL);

********
All I changed from your original statement was the m_hWnd (I changed it to NULL). For some reason or the other, my code compiler did not like it when you actually passed it the Window handle.

This should work, I tried looking for the same answer on this forum, but no one just came out and said it. I had to play around with the ShellExecute command before I got it just right.

sparafucile17
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top