createProcess() 不工作?

createProcess() not working?

我正在尝试在 windows visual studio 2012 professional windows 7.The 上使用 visual c++ 打开一个程序,代码会 运行 顺利但不会实际打开程序。我也根本没有收到任何构建错误。这是我的代码

#include <iostream>
#include <Windows.h>

int main ()
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    if (!
    CreateProcess
            (
            TEXT("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"),
            NULL,NULL,NULL,FALSE,
            CREATE_NEW_CONSOLE,
            NULL,NULL,
            &si,
            &pi
            )
            )
        {
            std::cout << "Unable to execute.";
        }

}

我正在尝试打开 google chrome 作为测试。另外,我从这个网站得到了部分代码和一些帮助 http://www.cplusplus.com/forum/beginner/48283/ 我将不胜感激任何帮助!

编辑:

现在我知道 createProcess 函数正在运行。如果我尝试用 C++ 打开文本文件,怎么会没有错误,但实际的文本记事本不会打开。这是代码

STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    if (!
    CreateProcess
            (
            TEXT("C:\Users\Mohammed Mehdi\Documents\Test\Test.txt"),
            NULL,NULL,NULL,FALSE,
            CREATE_NEW_CONSOLE,
            NULL,NULL,
            &si,
            &pi
            )
            )
        {
            cout << "Unable to execute.";
        }

我认为您缺少一个“\”。

而不是 TEXT("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")

试试看 TEXT("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")

对于问题的第二部分,您正在尝试使用自己的 txt 作为流程。那是行不通的。相反,使用记事本:

TEXT("C:\Users\Mohammed Mehdi\Documents\Test\Test.txt")

收件人:

TEXT("C:\windows\system32\notepad.exe /A C:\Users\Mohammed Mehdi\Documents\Test\Test.txt")