Set the default IE provider for IE using IOpenServiceManager :: InstallService

I would like to install the default search engine provider IE using IOpenServiceManager :: InstallService:

  • Give the link http://www.opensearch.org/Specifications/OpenSearch/1.1#OpenSearch_description_elements . I created SearchProviderInfo.xml as follows:

      <? xml version = "1.0" encoding = "UTF-8"?> 
    <OpenSearchDescription xmlns = "http://a9.com/-/spec/opensearch/1.1/">
    <ShortName> Web Search </ShortName>
    <Description> Use Example.com to search the Web. </Description>
    <Tags> example web </Tags>
    <Contact> admin@example.com </Contact>
    <Url type = "application / atom + xml"
    template = "http://example.com/?q={searchTermsasket&pw={startPage?asure&format=atom" />
    <Url type = "application / rss + xml"
    template = "http://example.com/?q={searchTermsasket&pw={startPage?asure&format=rss" />
    <Url type = "text / html"
    template = "http://example.com/?q={searchTermsasket&pw={startPage?}" />
    <LongName> Example.com Web Search </LongName>
    <Image height = "64" width = "64" type = "image / png"> http://example.com/websearch.png </Image>
    <Image height = "16" width = "16" type = "image / vnd.microsoft.icon"> http://example.com/websearch.ico </Image>
    <Query role = "example" searchTerms = "cat" />
    <Developer> Example.com Development Team </Developer>
    <Attribution>
    Search data Copyright 2005, Example.com, Inc., All Rights Reserved
    </Attribution>
    <SyndicationRight> open </SyndicationRight>
    <AdultContent> false </AdultContent>
    <Language> en-us </Language>
    <OutputEncoding> UTF-8 </OutputEncoding>
    <InputEncoding> UTF-8 </InputEncoding>
    </OpenSearchDescription>
  • Give the link http://msdn.microsoft.com/en-us/library/cc849088%28v=vs.85%29.aspx . I create the project "SetDefaultHelper" as follows:

      #include <windows.h>
         #include <atlbase.h>
         #include <wininet.h>
         #include <urlmon.h>
         #include <string>
         #include "openservice.h"    
         #pragma comment (lib, "urlmon.lib")
    
     void DisplayUsage ()
     {
         wprintf (L "\ r \ nSetDefaultHelper.exe - Call SetDefault API on a search provider");
         wprintf (L "\ r \ n");
         wprintf (L "\ r \ nUSAGE: SetDefaultHelper.exe <option>");
         wprintf (L "\ r \ n");
         wprintf (L "\ r \ nOptions (these are mutually exclusive!):");
         wprintf (L "\ r \ n");
         wprintf (L "\ r \ n / guid <guid> GUID of an installed search provider");
         wprintf (L "\ r \ n / url <url> URL of an OpenSearch Description file");
         wprintf (L "\ r \ n");
     }
    
     int __cdecl wmain (__ in int argc, __in_ecount (argc) WCHAR * argv [])
     {
         HRESULT hr = E_FAIL;
         BOOL fComInitialized = FALSE;    
         if (3! = argc)
         { 
             DisplayUsage ();
         }
         else if (SUCCEEDED (CoInitialize (NULL)))
         {
             fComInitialized = TRUE;
             CComPtr <IOpenServiceManager> spManager;
             hr = spManager.CoCreateInstance (CLSID_OpenServiceManager);    
             if (SUCCEEDED (hr))
             {
                 CComPtr <IOpenService> spService;    
                 if (0 == _wcsicmp (argv [1], L "/ guid"))
                 {
                     // Get an IOpenService pointer from the GUID.
                     WCHAR szEscaped [INTERNET_MAX_URL_LENGTH] = L "";
                     DWORD cchEscaped = ARRAYSIZE (szEscaped);
                     hr = UrlEscape (argv [2], szEscaped, & cchEscaped, URL_ESCAPE_SEGMENT_ONLY);    
                     if (SUCCEEDED (hr))
                     {                        
                         std :: wstring wsOsid (L "x-osid: 1: search:");
                         wsOsid + = szEscaped;
                         hr = spManager-> GetServiceByID (wsOsid.c_str (), & spService);
                     }  
                 }
                 else if (0 == _wcsicmp (argv [1], L "/ url"))
                 {
                     // Install the provider to get an IOpenService pointer.
                     // CComPtr <IUri> spUri;
                     // hr = CreateUri (argv [2], 0, 0, & spUri);
                     // if (SUCCEEDED (hr))
                     // {
                         hr = spManager-> InstallService (argv [2], & spService);
                     //}
                 }
                 else
                 {
                     DisplayUsage ();
                     hr = E_FAIL;
                 }
    
    
    if (SUCCEEDED(hr)) { hr = spService-&#62;SetDefault(TRUE, NULL); } } } if (fComInitialized) { CoUninitialize(); } return hr; 
    }
  • I will build the project in order. Both SetDefaultHelper.exe and SearchProviderInfo.xml files are the same folder. In the project setup, set "Configuration Properties"> "Debug"> "Arguments" = / url absolutePaht / searchProvider.xml . Then run debug (F10), in the line "hr = CreateUri (argv [2], 0, 0, & spUri);", rusult hr is so insignificant. I do not know why. Can you help me?

Many thanks.

[Allowed]:
1. No need to CreateUri // commented
2. Use absolutely the path.

+4
source share
1 answer

Use the absolute path and UrlCreateFromPath to create the file:/// url, pass that InstallService url.

Meanwhile, your XML seems to have an error.

  WCHAR szURL[MAX_PATH] = L""; DWORD cchURL = ARRAYSIZE(szURL); hr = ::UrlCreateFromPath(argv[2], szURL, &cchURL, 0); if (SUCCEEDED(hr)) { hr = spManager->InstallService(argv[2], &spService); // Now we can set it as the default. if (SUCCEEDED(hr)) { hr = spService->SetDefault(TRUE, NULL); if (hr == OS_E_CANCELLED) { hr = E_ACCESSDENIED; // by the user! } } } 
+3
source

Source: https://habr.com/ru/post/1399313/


All Articles