Re: VC++ 6.0, does not run with properly under Vista
Hi
I've found out the reason of the problem: it resides in VS++ 6.0!
I made a minimal MFC SDI app with VC6 SP6, added a menu command and put your
code in. It is running fine on Windows 2008 which is pretty much Vista, so I
am pretty sure it runs on Vista as well.
No matter of the verb you use (run, run as, open), it works fine - in
both XP and Vista - if compiled in Visual Studio 2005.
If compiled in VS++ 6.0 and executed under Vista, the verb "open" causes
a program crash, while "run as" makes the system to interpret the lpFile
"open" starts notepad for me. "runas" (no space, sorry my fault earlier!)
gives me the UAC dialog and starts notepad elevated.
Please show the exact params you pass.
Here is my menu handler. Can you also try a minimal sample app?
#define MAX_DIRNAME_LENGTH MAX_PATH
void CMainFrame::OnGo()
{
SHELLEXECUTEINFO si;
char folder_path[MAX_DIRNAME_LENGTH+1];
const char* application_path = "C:\\windows\\notepad.exe";
const char* command_line = "";
if( (application_path != NULL) && (application_path[0] != 0) ) // Be sure
there is something to work with
{
// Extract the directory path from the application path
strcpy( folder_path, application_path );
for( int i = strlen(folder_path)-1; i > 0; i-- )
{
if( (folder_path[i] == '\\') || (folder_path[i] == '/') )
{
folder_path[i] = 0;
break;
}
}
si.cbSize = sizeof(si);
si.fMask = SEE_MASK_NOCLOSEPROCESS;
si.hwnd = m_hWnd;
si.lpVerb = "open"; // or "runas" for UAC elevation
si.lpFile = application_path;
si.lpDirectory = folder_path;
si.lpParameters = command_line;
si.nShow = SW_SHOWNORMAL;
ShellExecuteEx( &si );
if( (int)(si.hInstApp) <= 32 )
{
AfxMessageBox("Error lauchning app", MB_OK|MB_ICONEXCLAMATION);
}
}
}
--
SvenC