shellexecuteex传递多个参数
时间: 2023-09-17 12:07:19 浏览: 129
使用ShellExecuteEx调用控制台程序(exe)并传入多个参数源码
ShellExecuteEx函数可以传递多个参数,例如:
```c++
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "C:\\Program Files\\MyProgram\\MyProgram.exe";
ShExecInfo.lpParameters = "param1 param2 param3";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
```
在这个例子中,lpParameters参数包含了三个参数,它们之间用空格隔开。你可以根据需要添加更多的参数。在MyProgram.exe程序中,你可以使用命令行参数来获取这些参数。例如,在C++中,你可以使用以下代码来获取这些参数并打印它们的值:
```c++
int main(int argc, char *argv[])
{
for (int i = 1; i < argc; i++)
{
cout << "Parameter " << i << ": " << argv[i] << endl;
}
return 0;
}
```
阅读全文