|
-
February 18th, 2009, 08:55 AM
#1
ShellExecute is not performing as expected
Good Morning,
I am a newbie to Visual C++ programming. I have been trying to extract files from a CAB by use of the ShellExecute command. I have made a batch file (CABTest.bat) that does the following:
expand Test.cab -f:*.* C:\Temp\CABStuff
I have converted the CABTest.bat into an exe file called CABTest.exe
I am then using the ShellExecute(...) as follows and nothing happens:
void CInstallerDlg::OnBnClickedShell()
{
// TODO: Add your control notification handler code here
HINSTANCE hInst = ShellExecute(0, L"open", L"c:\\Temp\\CABTest.exe", NULL, 0, SW_SHOW);
}
If I double-click the CABTest.exe file from my browser, the file are extracted. The path is correct because I've tried this out with notepad.exe from the same directory.
Does anyone have any suggestions as to what I done wrong?
Thanks,
Lee...
-
February 18th, 2009, 09:18 AM
#2
Re: ShellExecute is not performing as expected
Where is test.cab located ?
-
February 18th, 2009, 09:21 AM
#3
Re: ShellExecute is not performing as expected
What do you mean by:
I have converted the CABTest.bat into an exe file called CABTest.exe
Did you just rename it to .EXE?
-
February 18th, 2009, 09:23 AM
#4
Re: ShellExecute is not performing as expected
Hi,
The CAB is located in:
C:\Temp\CABStuff
Thanks...
-
February 18th, 2009, 09:26 AM
#5
Re: ShellExecute is not performing as expected
No,
I did not rename the file to *.exe. There is a Convert_batch_to_exe tool that converts a batch to an exe. It looks as if the ShellExecute requires an exe file.
Thanks
-
February 18th, 2009, 09:37 AM
#6
Re: ShellExecute is not performing as expected
Your are probably running your own program from another directory. Use SetCurrentDirectory to change to c:\temp instead of adding the path to the shellexecute.
It looks as if the ShellExecute requires an exe file.
Nope. It can run everything. If you run a mp3 file it will automagically start your mp3 player based on the mp3 extension.
-
February 18th, 2009, 09:52 AM
#7
Re: ShellExecute is not performing as expected
Thanks Skizmo,
Your reply prompted me to look at my path to the CAB file. I made an absolute path, converted the batch file to an exe file, ran it and it worked.
I still could not get it to run a bat file though.
Anyways, thanks a bunch!!!
Lee...
-
February 18th, 2009, 10:18 AM
#8
Re: ShellExecute is not performing as expected
You don't need to set current path because shellexecute have one parameter which is counted as current dir for executed program
ShellExecute(NULL, "open", "c:/mydir/myprg.exe", "", "c:/mydir/", SW_SHOWNORMAL);
you can also call batch files with this function:
ShellExecute(NULL, "open", "c:/mydir/extract.bat", "", "c:/mydir/", SW_SHOWNORMAL);
-
February 18th, 2009, 11:09 AM
#9
Re: ShellExecute is not performing as expected
you can use CreateProcess (comment the WaitForSingleObject if you dont need it):
Code:
bool execute_wait( char* file )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
file, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
return false;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return true;
}
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
|