#include <stdio.h>
#include <windows.h>
#include <Wincrypt.h>
#pragma comment(lib,"crypt32.lib")
#pragma comment(lib,"cryptui.lib")
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
typedef struct _ENUM_ARG
{
const void *pvStoreLocationPara;
} ENUM_ARG, * PENUM_ARG;
static BOOL WINAPI EnumPhyCallback(
const void *pvSystemStore,
DWORD dwFlags,
LPCWSTR pwszStoreName,
PCERT_PHYSICAL_STORE_INFO pStoreInfo,
void *pvReserved,
void *pvArg);
static BOOL WINAPI EnumSysCallback(
const void *pvSystemStore,
DWORD dwFlags,
PCERT_SYSTEM_STORE_INFO pStoreInfo,
void *pvReserved,
void *pvArg);
static BOOL WINAPI EnumLocCallback(
LPCWSTR pwszStoreLocation,
DWORD dwFlags,
void *pvReserved,
void *pvArg);
void main(void)
{
//-------------------------------------------------------------------
// Declare and initialize variables.
DWORD dwExpectedError = 0;
DWORD dwLocationID = CERT_SYSTEM_STORE_CURRENT_USER_ID;
DWORD dwFlags = 0;
ENUM_ARG EnumArg;
LPSTR pszStoreParameters = NULL;
LPWSTR pwszStoreParameters = NULL;
LPWSTR pwszSystemName = NULL;
LPWSTR pwszPhysicalName = NULL;
LPWSTR pwszStoreLocationPara = NULL;
void *pvStoreLocationPara;
DWORD dwNameCnt = 0;
HKEY hKeyRelocate = HKEY_CURRENT_USER;
LPSTR pszRelocate = NULL;
HKEY hKeyBase = NULL;
//-------------------------------------------------------------------
// Initialize data structure variables.
pvStoreLocationPara = pwszStoreLocationPara;
memset(&EnumArg, 0, sizeof(EnumArg));
//EnumArg.dwFlags = dwFlags;
//EnumArg.hKeyBase = hKeyBase;
//EnumArg.pvStoreLocationPara = pvStoreLocationPara;
//EnumArg.fAll = TRUE;
printf("Begin enumeration of store locations. /n");
if(CertEnumSystemStoreLocation(
dwFlags,
&EnumArg,
EnumLocCallback
))
{
printf("/nFinished enumerating locations. /n");
}
else
{
printf("Enumeration of locations failed.");
}
} // End of main
static BOOL WINAPI EnumSysCallback(
const void *pvSystemStore,
DWORD dwFlags,
PCERT_SYSTEM_STORE_INFO pStoreInfo,
void *pvReserved,
void *pvArg)
//-------------------------------------------------------------------
// Begin callback process.
{
//-------------------------------------------------------------------
// Declare and initialize local variables.
PENUM_ARG pEnumArg = (PENUM_ARG) pvArg;
static int line_counter=0;
char x;
//-------------------------------------------------------------------
// Begin processing.
//-------------------------------------------------------------------
// Control break. If 5 or more lines have been printed,
// pause and reset the line counter.
if(line_counter++ > 5)
{
printf("Enumeration of system store: Press Enter to continue.");
scanf("%c",&x);
line_counter=0;
}
//-------------------------------------------------------------------
// Prepare and display the next detail line.
printf(" %S/n", pvSystemStore);
if (!CertEnumPhysicalStore(
pvSystemStore,
dwFlags,
pEnumArg,
EnumPhyCallback
))
{
DWORD dwErr = GetLastError();
if (!(ERROR_FILE_NOT_FOUND == dwErr ||
ERROR_NOT_SUPPORTED == dwErr))
{
printf(" CertEnumPhysicalStore");
}
}
return TRUE;
}
static BOOL WINAPI EnumPhyCallback(
const void *pvSystemStore,
DWORD dwFlags,
LPCWSTR pwszStoreName,
PCERT_PHYSICAL_STORE_INFO pStoreInfo,
void *pvReserved,
void *pvArg )
{
//-------------------------------------------------------------------
// Declare and initialize local variables.
PENUM_ARG pEnumArg = (PENUM_ARG) pvArg;
printf(" %S", pwszStoreName);
printf("/n");
return TRUE;
}
static BOOL WINAPI EnumLocCallback(
LPCWSTR pwszStoreLocation,
DWORD dwFlags,
void *pvReserved,
void *pvArg)
{
//-------------------------------------------------------------------
// Declare and initialize local variables.
PENUM_ARG pEnumArg = (PENUM_ARG) pvArg;
static int linecount=0;
CertEnumSystemStore(
dwFlags,
(void *) pEnumArg->pvStoreLocationPara,
pEnumArg,
EnumSysCallback );
//}
return TRUE;
}