-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_installed_apps.cpp
51 lines (46 loc) · 1.72 KB
/
query_installed_apps.cpp
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
#include <windows.h>
#include <stdio.h>
#define BUFF_MAX_LEN 4096
void GetInstalledSoft (char *ResultBuff,DWORD BuffLen);
void GetInstalledSoft (char *ResultBuff,DWORD BuffLen)
{
HKEY hKey,hItemKey;
char ItemKey[BUFF_MAX_LEN],Data[BUFF_MAX_LEN],
SoftName[BUFF_MAX_LEN],SoftVersion[BUFF_MAX_LEN];
DWORD cbItemKey=sizeof(cbItemKey),cbData=sizeof(Data),
cbSoftName=sizeof(SoftName),cbSoftVersion=sizeof(SoftVersion),
i = 0, type;
memset(ResultBuff, 0, BuffLen);
memset(Data, 0, cbData);
if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", &hKey))
{
return;
}
while (RegEnumKeyA(hKey, i++, Data, cbData) == 0) {
cbSoftName=BUFF_MAX_LEN;
cbSoftVersion=BUFF_MAX_LEN;
memset(SoftName, 0, cbSoftName);
memset(SoftVersion, 0, cbSoftVersion);
memset(ItemKey, 0, cbItemKey);
sprintf(ItemKey,"%s\\%s","Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",Data);
if (RegOpenKeyA(HKEY_LOCAL_MACHINE, ItemKey, &hItemKey)) {
return;
}
RegQueryValueExA(hItemKey, "DisplayName", 0, &type, SoftName, &cbSoftName);
RegQueryValueExA(hItemKey, "DisplayVersion", 0, &type, SoftVersion, &cbSoftVersion);
RegCloseKey(hItemKey);
if (SoftName[0]!=0) {
sprintf(ResultBuff,"%s[IS] [Name: %s] [Vesion: %s]\n", ResultBuff, SoftName, SoftVersion);
}
}
RegCloseKey(hKey);
return;
}
void main( int argc, char **argv )
{
char *InstalledSoftList;
InstalledSoftList=malloc(BUFF_MAX_LEN);
GetInstalledSoft(InstalledSoftList,sizeof(InstalledSoftList));
printf("\nInstalled Software:\n%s\n",InstalledSoftList);
return;
}