0

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 Answers1

0

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);
Doepey
  • 24
  • 3
  • Thank You for Your solution, but unfortunately doesn't solve my problem. – user3601471 May 05 '14 at 16:51
  • It works with classic URL, but I have to type there exactly \\192.168.1.5. Because it isn't classic http protocol, but it should be smb protocol. And I dont know, how to put there the parameter \\192.168.1.5 to the IE. When I as a paremeter choose classic url address, it works. But when I let there that what I need (\\192.168.1.5), IE just ignores it. – user3601471 May 05 '14 at 16:57
  • Did you try opening your URL in the file explorer? I know for sure that the windows explorer supports SMB/CIFS. Also, try typing "file:\\192.168.1.5" or even try "\\\192.168.1.5" in both explorers if you can. Let me know what happens and I'll update my code for you. I don't have an SMB server setup or I'd test it myself. :P – Doepey May 05 '14 at 18:35
  • You're right. Works in file explorer :) So now the goal is just open a windows file explorer in new window and type there \\192.168.1.5 :) – user3601471 May 05 '14 at 18:43
  • I updated the answer, try the last example and let me know what happens. – Doepey May 05 '14 at 18:58
  • Well, the window of explorer does open, but not on the smb server folder but in Documents folder. In all ceses (\\192.168.1.5 or file:\\192.168.1.5 or even \\192.168.1.5). – user3601471 May 05 '14 at 19:11
  • Last thing I can think of is to type your url in the file explorer manually. Then right click and copy the link text. Make sure when you paste it into strURL that you are using proper escape sequences. ie ("\\"). So typing "\\192.168.1.5" should be "\\\\192.168.1.5" – Doepey May 05 '14 at 19:19
  • I am quite sure, that I'm using correct syntaxy. It works only, when str.URL is a path to some folder on local disc (D:\\Movies\\ for example). But when I try to access this smb server or another computer in my local site, that works as smb server too, it just opens in the Documents foler. – user3601471 May 05 '14 at 19:24
  • File explorer opens your document folder by default if it can't figure out the parameter you are sending to it. I just tested on my computer using "\\\\192.168.1.8" with the example above and it worked fine =/ – Doepey May 05 '14 at 19:30
  • Finally :) It took quite a while, so I thought that it doesn't working, but after cca 20 secons it opened. Thanks a lot man :) – user3601471 May 05 '14 at 19:38