CreateProcess 的lpCurrentDirectory参数用来设置子进程工作路径,说是一个指向一个以NULL结尾的字符串,且要包含驱动器名的绝对路径,但是这个参数一般都为null,我尝试用这个参数设置子进程的工作路径,
createprocess函数总是返回2(找不到工作路径),这个情况该怎么解决,大家有用过这个参数,给个样本参照下吗,求大神指点

解决方案 »

  1.   

    楼主可以用GetModuleFileName来获取绝对路径然后拼接达到目的
      

  2.   

    CreateProcess 你怎么写的呢,你是GetLastError 
    ERROR_FILE_NOT_FOUND
    2
    The system cannot find the file specified.是说文件没找到啊,你确定CreateProcess 的  LPCTSTR lpApplicationName 没错吗 
      

  3.   

    if(!CreateProcess(NULL,szChildProcessCmd,NULL,NULL,FALSE,0,NULL,"E:\\",&si,&pi))
    {
    printf("CreateProcess fialed (%d).\n",GetLastError());
    return 1;
    }
      

  4.   

    The first parameter, lpApplicationName, can be NULL, in which case the executable name must be in the white space–delimited string pointed to by lpCommandLine. If the executable or path name has a space in it, there is a risk that a different executable could be run because of the way the function parses spaces. The following example is dangerous because the function will attempt to run "Program.exe", if it exists, instead of "MyApp.exe".
    LPTSTR szCmdline = _tcsdup(TEXT("C:\\Program Files\\MyApp -L -S"));
    CreateProcess(NULL, szCmdline, /* ... */);
    If a malicious user were to create an application called "Program.exe" on a system, any program that incorrectly calls CreateProcess using the Program Files directory will run this application instead of the intended application.
    To avoid this problem, do not pass NULL for lpApplicationName. If you do pass NULL for lpApplicationName, use quotation s around the executable path in lpCommandLine, as shown in the example below.
    LPTSTR szCmdline[] = _tcsdup(TEXT("\"C:\\Program Files\\MyApp\" -L -S"));
    CreateProcess(NULL, szCmdline, /*...*/);
    楼主贴出szChildProcessCmd的内容吧,
      

  5.   

    我把lpCurrentDirectory这个参数置为null程序是能正常运行的,我就是想通过这个参数设置子进程的工作目录
      

  6.   


    能正常运行?createprocess函数总是返回2(找不到工作路径)?我不太理解,也很好奇,楼主可以贴出szChildProcessCmd的内容不,以及如何获得返回2的,GetLastError吗?
      

  7.   

    把lpCurrentDirectory这个参数置为null程序能正常运行的,如果设置了lpCurrentDirectory参数就返2,
    而且我问的是倒数第三个参数,不是第二参数.