InternetOpenUrl does not work from a virtual machine

295 views Asked by At
Setup:
Oracle Virtual Box 6.1
Windows 7 Home Premium x86 and x64

I have the following code running from a Virtual Machine in both versions of win7 32 and 64 bit:

#include <iostream>
#include <Windows.h>
#include <WinInet.h>
#include <thread>

#pragma comment(lib, "wininet.lib")

using namespace std;

bool isURL_Redirected(wstring url)
{
    HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

    if (hInternet)
    {
        hInternet = InternetOpenUrl(hInternet, url.c_str(), 0, 0, INTERNET_FLAG_NO_AUTO_REDIRECT, 0);
        WCHAR lpvData[1000];
        DWORD size = sizeof(lpvData);

        if (hInternet)
        {
            if (HttpQueryInfo(hInternet, HTTP_QUERY_LOCATION, lpvData, &size, NULL))
            {
                InternetCloseHandle(hInternet);
                return true;
            }
        }
        else
        {
            cout << "line 30: " << GetLastError() << endl;
        }
    }
    else
    {
        cout << "line 35: " << GetLastError() << endl;
    }

    InternetCloseHandle(hInternet);
    return false;
}

int main()
{
    if (isURL_Redirected(L"https://download.visualstudio.microsoft.com/download/pr/8e396c75-4d0d-41d3-aea8-848babc2736a/80b431456d8866ebe053eb8b81a168b3/ndp462-kb3151800-x86-x64-allos-enu.exe"))
        cout << "It does redirect." << endl;
    else
        cout << "It does not redirect." << endl;
    system("pause"); // Win only.
}

Outputs:

line 30: 12157

Why it does not work from a Virtual Machine? It works fine in a real machine though. I noticed that if I change the URL to https://www.google.com it works fine, so I truly believe there's something to do with the URL and the Virtual Machine. Is there a workaround for this?

EDIT

12157 is an internal WinInet error, usually when it can't load its SSL/TLS library. It has nothing to do with sending keys to the HTTPS server.

0

There are 0 answers