Why is InternetOpenURL reporting error 2 (the system cannot find the file specified)?

The Internet access code in our product works fine for 99.99% of people. However, for some of them, this simply does not work. We added some trace code to try to find out what the problem is, and it turns out that InternetOpenURL reports error 2 - "The system cannot find the specified file" - from this function call:

options = INTERNET_FLAG_RAW_DATA | INTERNET_FLAG_RESYNCHRONIZE; handle = InternetOpenUrl(internet,url,NULL,0,options,0); 

(The Internet is a handle to an Internet connection opened with InternetOpen, url is the URL of a simple text file that exists on our web server.)

We test two different websites: one http and one https, which are located in completely different places (different domains, servers are located geographically separately), and they both give the same error for this guy and several others. 99% of people, including ourselves, can access them without any problems. In addition, affected people can access the same URLs without problems in their web browsers.

What could be here ?: (

EDIT : fortunately, we found out what happened wrong! It turns out that some people have the "Use a proxy server for your local network" checkbox set in their Internet options, without actually specifying a proxy server. We tried to use non-existent proxy server data and, of course, we ran into problems.

I still need to research a software solution for this, but anyone who reports a problem solves this problem with this solution:

  • Open Internet Explorer
  • Go to Tools → Internet Options
  • Click the Connections tab.
  • At the bottom there should be a button that says "LAN settings." Click on it.
  • In the "Proxy server" field, uncheck "Use a proxy server for your local network"
  • Click OK for everyone, restart Windows and try connecting to the Internet again through the product.

I have no idea why so many people have a checkbox, but a proxy server is not listed. But, apparently, this is what needs to be done to fix it.

+4
source share
5 answers

GetLastError() is probably not the best way to find out what went wrong. From docs :

To determine why access to the service was denied, call InternetGetLastResponseInfo .

+2
source

Given this information, I would suggest that these users have a firewall (or some type of security software) that plugs in wininet and interferes with your call. In addition, they may have a malware infection.

+2
source

The solution may be as simple as opening Internet Explorer. I never use a browser, but a Windows update broke calls in InternetOpenUrl.

Opening IE will configure the settings so that the proxy information works again. Note that this is important when using INTERNET_OPEN_TYPE_PRECONFIG in InternetOpen ().

Initially, I saw problems only when INTERNET_FLAG_RELOAD was installed, but soon everything got worse, so simple vanilla compounds also failed.

tl; dr Open IE so that it can bless your system.

+2
source

Do these users use proxies? If they have a proxy server in IE, it is possible that the information is picked up and causes errors.

In addition, I agree with Hugh. GetLastError () can sometimes be misleading. If you want to use this, you must make sure that SetLastError (0) before you make your call, otherwise you could get the error code set by some previous method call.

+1
source

Try the following:

On error, hook the SetLastError function (manually using hot-patch or using MS Detours or something else) and call InternetOpenUrl again.

In the hooking function, if the argument is SetLastError in't zero, make a mini-drive. You will get the place where this error is installed.

+1
source

All Articles