int GetUserName(char* szUserName)
{
#ifdef _DEBUG
CHAR szEchoStr[256];
#endif
DWORD nCount = 0;
HRESULT hres;
// Initialize COM.
hres = CoInitialize(NULL);
if (FAILED(hres))
{
#ifdef _DEBUG
sprintf(szEchoStr, "CoInitiaLize: %x", hres);
OutputDebugString(szEchoStr);
#endif
return 1; // Program has failed.
}
// Initialize
hres = CoInitializeSecurity(
NULL,
-1, // COM negotiates service
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
if (FAILED(hres))
{
if(hres != RPC_E_TOO_LATE)
{
#ifdef _DEBUG