CreateProcess的配置问题不是很清楚
比如我想启动d:\temp\test.exe
我应该怎么写语句?
关于路径的字符串的话一定要是什么类型的啊。

解决方案 »

  1.   

    MSDN 翻到 CreateProcess 函数处,你就可以发现他有个例子
    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). 
            TEXT("MyChildProcess"), // Command line.   把这里的 "MyChildProcess" 替换成 "d:\temp\test.exe" 就OK了
            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;
        }
      

  2.   

    厄现在的问题是抛出System.AccessViolationException异常
    该怎么解决?
      

  3.   

    CString tepfile="d:\\temp\\test.exe";1.如果单单地想运行一个程序,可以用WinExec(,SW_SHOW);2.
    PROCESS_INFORMATION pi;
    STARTUPINFO si;
    ZeroMemory(&si, sizeof(si));
    用CreateProcess(NULL, tepfile.GetBuffer(tepfile.GetLength()),
    NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)