0
votes

I am writing a simple console application in C++, that connects my Android tablet with PC.

To do so, I have to type "\\192.168.1.5" into Internet Explorer (doesn't work anywhere else). 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 \\.

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?

1

1 Answers

0
votes

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).

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. Be sure to leave the directory parameter 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);