首先,我已经阅读了网络上与此功能相关的所有内容,但仍然无法正常使用。我在这里使用msdn页面中使用的相同示例:
http://msdn.microsoft.com/en-us/library/ms682512(VS.85).aspx
我的代码:
#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 );
}
如您所见,我只更改了目录部分。当我运行它不会给出任何错误但它也无法正常工作。