简体   繁体   English

MFC命令窗口命令

[英]MFC Command Window Command

In MFC I want to Create a process by opening Command Window and executing a command in that say open notepad. 在MFC中,我想通过打开“命令窗口”并在打开的记事本中执行命令来创建进程。
i Found this tried it didn't work 我发现这个尝试不起作用

STARTUPINFO sInfo = {0};
sInfo.cb = sizeof(sInfo);
PROCESS_INFORMATION pInfo = {0};

CreateProcess("C:\\WINDOWS\\System32\\cmd.exe",""0,0,TRUE,
NORMAL_PRIORITY_CLASS,0,0,&sInfo,&pInfo);

You're not telling cmd to do anything. 您没有在告诉cmd做任何事情。 Try this: 尝试这个:

CreateProcess(0, "C:\\WINDOWS\\System32\\cmd.exe /c notepad.exe", 0, 0, TRUE, 0, 0, 0, &sInfo, &pInfo);

But maybe this is easier 但这也许更容易

ShellExecute(0, "open", "cmd.exe", "/C notepad.exe", 0, SW_HIDE);

Or even this: 甚至这个:

system("notepad.exe");

Go to the MSDN document we can see, you don't specify the second parameter that is the command line to excute. 转到我们可以看到的MSDN文档,您无需指定第二个参数即要执行的命令行。

On the other hand, there are no NORMAL_PRIORITY_CLASS enum item for the sixth parameter. 另一方面,第六个参数没有NORMAL_PRIORITY_CLASS枚举项。 You should do like this: 您应该这样做:

STARTUPINFO si = { sizeof(si) };   
PROCESS_INFORMATION pi;   

si.dwFlags = STARTF_USESHOWWINDOW;   
si.wShowWindow = TRUE;  
TCHAR cmdline[] =TEXT(" notepad.exe");   
BOOL bRet = ::CreateProcess (   
    TEXT("C:\\WINDOWS\\System32\\cmd.exe"),  
    cmdline,    
    NULL,   
    NULL,   
    FALSE,   
    CREATE_NEW_CONSOLE,   
    NULL,   
    NULL,   
    &si,   
    &pi);   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM