Reputation: 509
First off, I've read everything on the net related to this function for a few days but still couldn't get it right. I'm using the same example used in msdn page here:
http://msdn.microsoft.com/en-us/library/ms682512(VS.85).aspx
My code:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
void _tmain( int argc, TCHAR *argv[] )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
SecureZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
SecureZeroMemory( &pi, sizeof(pi) );
if( argc != 2 )
{
printf("Usage: %s [cmdline]\n", argv[0]);
return;
}
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
"C:\\Users\\user\\Desktop\\FreeCell.lnk", // 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
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
As you see i've only changed the directory part. When i run it doesn't give any error but it is also not working.
Upvotes: 1
Views: 504
Reputation: 942197
CreateProcess can only start executable programs. For a .lnk file you'll need help from the shell. Use ShellExecuteEx() with the "open" verb.
Upvotes: 10