开发者

ShellExecute using an URL is resulting in unassociated error message. Which file association is missing?

开发者 https://www.devze.com 2023-02-28 06:21 出处:网络
I am using \"ShellExec\" in c++ and windows to open an url in the default browser. For very few customers it is failing with the following message:\"This file does not have a program associated with

I am using "ShellExec" in c++ and windows to open an url in the default browser.

For very few customers it is failing with the following message:"This file does not have a program associated with it for performing this action". I understand that this means that the "http" file type association is missing or invalid in the registry for开发者_如何转开发 this customer.

Questions:

Can I detect this issue programatically and fix or avoid it? - I was thinking of using AssocQueryKey and RegQueryValueEx, but not sure this is possible.

I appreciate any advice on fixing this. I do not have a system that shows the problem, so I am hoping that someone here has already solved the problem.

This is the code to open the browser. urlToNavigateTo would be something like "http://www.website.com/function?key=9271"

    ErrorClass error;
    SHELLEXECUTEINFO execInfo;
    ZeroMemory (&execInfo, sizeof(SHELLEXECUTEINFO));
    execInfo.cbSize     = sizeof(SHELLEXECUTEINFO);
    execInfo.lpFile     = urlToNavigateTo.c_str();
    execInfo.nShow      = SW_SHOWNORMAL;
    execInfo.hwnd       = m_hWnd;   // parent window for error messages 
    BOOL bOK            = ShellExecuteEx (&execInfo);
    if (bOK!=TRUE) {
        STRING errMessage = _T("Could not navigate to url Reason:" )+ FACTORY->GetUtils()->GetPlatformErrorMessage(GetLastError());
        LOG_ERROR(errMessage);
        error.Assign(errMessage);
    }


You are not telling what action you want to perform. In this case, the action you want is open.

ShellExecute(0, "open", "http://www.website.com/function?key=9271", 0, 0, SW_SHOWNORMAL);

With ShellExecuteEx, it means you would add :

execInfo.lpVerb = "open"
0

精彩评论

暂无评论...
验证码 换一张
取 消