我试图打开使用Visual C程序++ Windows上的Visual Studio 2012专业在Windows 7,代码将平稳运行,但实际上不会打开该程序。我还没有在所有得到任何构建错误。这里是我的代码
#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.";
}
}
我试图打开谷歌浏览器作为测试试。另外,我得到了这部分代码,并从本网站一些帮助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")