使用 ShellExecute c++ 打开长网址
Open long url using ShellExecute c++
我正在尝试使用 ShellExecute()
打开一个网址。该 url 由我的程序为长 http get 请求生成,ShellExecute()
不起作用并且没有显示响应。
ShellExecute(NULL, _T("open"), url, NULL, NULL, SW_SHOWNORMAL); // Does nothing when url is too long
比我为同一个命令编写了一个批处理文件,当 url 长度大于 259 个字符时,它会显示此错误:
start "" "{mywebsite}/&&&&..." // Repeating &
Windows cannot find
'{my-url}/{long-get-request} ....
Make sure you typed the name correctly, and then try again.
扩展ShellExecute()
字符限制的任何想法?或者也许是一个很酷的解决方案,除了ShellExecute()
或system()
或System::Diagnostics::Process::Start()
之外,打开一个长网址,它们都无法正常工作。
将
链接复制到 *.html 文件的建议将起作用,但是ShellExecute
将运行与*.html
关联的程序,而不是http:
。从理论上讲,这些关联可能是不同的。如果您不在乎,那么只需找到与*.html
的关联并使用CreateProcess
,如下所示:
std::wstring url = L"http://localhost/fake.php?123";
wchar_t buf[MAX_PATH] = { 0 };
DWORD size = _countof(buf);
AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".html", 0, &buf[0], &size);
std::wstring cmd(buf);
cmd += L" ";
cmd += url;
PROCESS_INFORMATION pi;
STARTUPINFO si{ sizeof(si) };
CreateProcess(0, &cmd[0], 0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0, 0, &si, &pi);
...
在 Windows 10 中,ShellExecute
接受大型参数行。
我想我有一个解决方案,但这可能不是最好的解决方案。基本上,我创建了一个重定向到我的长网址的 html 文件。
private: Void showPage(const string& httpGetString) {
string url = "{my-website}?" + httpGetString;
remove("jumper.html");
string htmlJumper = "<html><meta http-equiv="refresh" content="0; url=" + url + ""</html>";
fstream jumperFile;
jumperFile.open("jumper.html", ios::out);
jumperFile << htmlJumper;
jumperFile.close();
ShellExecute(NULL, _T("open"), L"jumper.html", NULL, NULL, SW_SHOWNORMAL);
}
相关文章:
- 是否可以将要"ShellExecute"的文件包含在 dll 中?如果是这样,"ShellExecute"中的文件位置应该是什么?
- ShellExecute(和ShellExecuteEx)对我的URL不做任何事情
- C Windows.h如何在Shellexecute中使用变量
- ShellExecute 中的 cmd 命令
- ShellExecute 返回成功,但不执行文件
- C++ - 使用 Windows Photo Viewer 使用 ShellExecute 打开图像
- 如何使用http:uri方案启动默认的Web浏览器并使用Shellexecute访问主页
- 浏览器中的ShellExecute url并不总是将焦点设置在浏览器上
- 如何调用 ShellExecute 以使用 C++ 打开具有特定程序的文件,而无需关联相同的文件扩展名
- ShellExecute in _beginthread
- 使用 ShellExecute c++ 打开长网址
- ShellExecute 以在 C++ 中打开.exe
- 将多个cmd.exe参数/参数传递给Shellexecute(ex)
- 如果我输入错误的 dos 命令,shellexecute 会给出正确的结果
- 为什么ShellExecute不能使用包含文件路径的LPCSTR变量
- 如何使用 CreateProcess 或 ShellExecute 来执行管道命令
- 如何在程序中调用 2 个或多个 shellexecute 函数
- MFC中的Shellexecute不会打开Adobe XI
- Visual C++ ShellExecute problems
- ShellExecute 未打开 HTML 文件