[英]How to add parameter to Internet Explorer using ShellExecute
I am writing a simple console application in C++, that connects my Android tablet with PC. 我正在用C ++编写一个简单的控制台应用程序,它将Android平板电脑与PC连接起来。
To do so, I have to type "\\\\192.168.1.5" into Internet Explorer (doesn't work anywhere else). 为此,我必须在Internet Explorer中键入“ \\\\ 192.168.1.5”(在其他任何地方都无法使用)。 So I wanted to write a simple application to do it instead of me.
所以我想写一个简单的应用程序代替我。 But Internet Explorer doesn't want to except the parameter starting with \\\\.
但是Internet Explorer不想除了以\\\\开头的参数。
This code works perfectly with opening a web page, but it doesn't solve my problem. 此代码与打开网页完美配合,但不能解决我的问题。
#include "stdafx.h"
#include "Windows.h"
int _tmain(int argc, _TCHAR* argv[]){
LPCTSTR open = L"open";
LPCTSTR file = L"iexplore.exe";
LPCTSTR path = L"C:\Program Files\Internet Explorer";
LPCTSTR parameters = L"\\192.168.1.5";
ShellExecute(NULL, open, file, parameters, path, SW_SHOWNORMAL);
return 0;
}
Can you suggest a solution please? 您能提出解决方案吗?
Don't forget your escape sequences :) 不要忘记您的转义序列:)
LPCTSTR path = L"C:\Program Files\Internet Explorer";
should be 应该
LPCTSTR path = L"C:\\Program Files\\Internet Explorer\\";
Below is a working example of what you want to do: (using the C++ String object). 下面是您想做的工作示例:(使用C ++ String对象)。
String strAction = "open";
String strURL = "http://192.168.1.5";
String strFile = "iexplore.exe";
String strPath = "C:\\Program Files\\Internet Explorer\\";
ShellExecute(NULL, strAction.c_str(), strFile.c_str(), strURL.c_str(), strPath.c_str(), SW_SHOWNORMAL);
If you want to just open the url in your default browser you could simply do this: 如果您只想在默认浏览器中打开网址,则可以执行以下操作:
String strAction = "open";
String strURL = "http://192.168.1.5";
ShellExecute(NULL, strAction.c_str(), strURL.c_str(), NULL, NULL, SW_SHOWNORMAL);
Use this code below to open your URL in windows file explorer. 使用下面的代码在Windows文件资源管理器中打开您的URL。 Be sure to leave the directory parameter
NULL
. 确保保留目录参数
NULL
。
String strAction = "open";
String strURL = "file:\\\\192.168.1.5";
String strFile = "explorer.exe";
ShellExecute(NULL, strAction.c_str(), strFile.c_str(), strURL.c_str(), NULL, SW_SHOWNORMAL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.