Getting program version of google chrome

hello,

I'm trying to make a program that checks if chrome is up to date. i came up with this code:
code]#include <stdio.h>
#include <iostream>

void getversion();

int main(){

getversion();

return 0;
}
void getversion(){

FILE *pd = popen("google-chrome --version", "r");
char output[50];
fgets(output,50,pd);
pclose(pd);
for (int i = 0; i <= 50; i++)
cout << output[i];
}
[/code]

this code works on my linux pc but not on windows. and specialy this line:
FILE *pd = popen("google-chrome --version", "r");

also the google chrome can't be found. how can i fix these problems
Last edited on
Google Chrome auto updates.
i just want to try this kind of programming
> this code works on my linux pc but not on windows.

_popen() http://msdn.microsoft.com/en-us/library/96ayss4b.aspx


> also the google chrome can't be found.

Search for chrome.exe.
still can't find the program. not with google-chrome.exe or only chrome.exe
You need either provide full path to executable or make sure that chrome.exe is in one of system search path.
but everybody's path is different on his computer. how can i test this
how can i test this
Poke the registry. It should hold information about install path.

Alternatively ask user to provide full path.
At the command prompt: >dir c:\*chrome.exe /s
I feel your pain here OP, this is because specifically Google Chrome and a handful of other otherwise excellent applications don't register with WMI like they should. Luckily, on Windows, the other 91% of the applications out there will allow you to pull the version numbers from WMI like this (example with Java because it often has multiple concurrent installations):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>

#define _WIN32_WINNT 0x06000000 //Windows 7
#define WINVER 0x601 //Window 7
#define WIN32_LEAN_AND_MEAN //Prevents Older Header Files From Being Included

#include <windows.h>
#include <winbase.h>
#include <Objbase.h>
#include <wbemidl.h>
#include <OleAuto.h>


int main()
{
    CoInitializeEx(NULL, COINIT_MULTITHREADED);

    IWbemLocator* pLocation  = NULL;
    IWbemServices* pService = NULL;

    BSTR Query = SysAllocString(L"Select * From Win32_Product Where Name Like '%Java%'"); ///This Is In WQL Which Is Not Unlike SQL.

    IEnumWbemClassObject* ClassEnum = NULL;
    IWbemClassObject*     ClassObj  = NULL;

    const ULONG NumItems = 1;
    ULONG ItemsRet = 0;

    VARIANT Version;
        VariantInit(&Version);
        V_VT(&Version) = VT_BSTR;

    CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
    CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*) &pLocation);
    pLocation->ConnectServer(BSTR(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &pService);
    pService->ExecQuery(BSTR(L"WQL"), BSTR(Query), WBEM_FLAG_BIDIRECTIONAL, NULL, &ClassEnum);

    while(ClassEnum->Next(WBEM_INFINITE, NumItems, &ClassObj, &ItemsRet) == WBEM_S_NO_ERROR)
    {
        ClassObj->Get(BSTR(L"Version"), 0, &Version, NULL, NULL);

        std::wcout << L"Version is: " << Version.bstrVal << L"\n";

        ClassObj->Release();
    }

    SysFreeString(Query);

    if(ClassEnum != NULL)
    {
        ClassEnum->Release();
    }

    if(pService != NULL)
    {
        pService->Release();
    }

    if(pLocation != NULL)
    {
        pLocation->Release();
    }

    CoUninitialize();

    return 0;
}


Obviously you would replace the part where is says '%Java%' with the name of the application you are looking for. NOTE that the percentage signs are wild cards. So for instance, if you wanted the versions of either OpenOffice or Libre Office but you wanted to exclude the versions of Microsoft office then the query would look like this:
Select * From Win32_Product Where Name Like '%Office%.%'
Because Microsoft office products do not contain a period in their name fields.

It is even possible to get this information from a remote machine with few modifications.

IMPORTANT_NOTE: The query for Win32_Product is not optimized for speed so this will take a minute or two. Most other COM operations are much faster, but this one is not.

EDIT: I forgot to list the libraries that you need to link to:
msvcrt.lib
ole32.lib
wbemuuid.lib
OleAut32.lib
Last edited on
Topic archived. No new replies allowed.