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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute() doesn´t work

Status
Not open for further replies.

mamaza

Programmer
Nov 28, 2001
3
DE
I want to program a MFC application which compacts
MS Access databases.
for this I use the following function:

void CCompactDlg::OnCompactButton()
{
UpdateData(true);
CString parameter ("/user administrator /pwd ");
parameter += m_passwort;
parameter += " /compact";
ShellExecute(NULL,NULL, LPCTSTR(m_dbname) ,LPCTSTR(parameter),"",SW_SHOWNORMAL);
}

normally, when you open a MS Access database with the argument "/compact" from command line, the database is opened for a short time and will automaticly closed after comprimission

but when I click on the CompactButton in my application,
the database opens and stays open

what´s wrong?

can anybody help?
(sorry for that english)

 
Well one thing you can try is to capture the window handle (hWnd) in the ShellExecute function (which is NULL in your example), and then use sendkeys to send alt-f4 to the program... that should close it (I think....)

Unless, there is another function that will take the hWnd and close it.. I don't know if destroying a window is what you want, but if so, it can be done quite easily with a one or two lines of code. check out the help in MS VC++

Hope that helps.

MG
 
If you want to close the database a short time after you've open it,try this:

HWND hwnd = FindWindow( NULL, "window's title" );
Sleep( delay ); // you choose any specific delay value
PostMessage( hwnd, SC_CLOSE, 0, 0 );
 
This is just a suggestion... Maybe WinExec will work if there's an .exe file that compact a database but I didn't check it...

WinExec ( "C:\\msaccess.exe database.mdb /compact", SW_SHOWNORMAL );

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top