Click here to Skip to main content
15,908,172 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Any One Care To Explain Why My Messages are Voted Down? Pin
Prakash Nadar9-Jan-06 17:50
Prakash Nadar9-Jan-06 17:50 
GeneralRe: Any One Care To Explain Why My Messages are Voted Down? Pin
ThatsAlok9-Jan-06 17:56
ThatsAlok9-Jan-06 17:56 
GeneralRe: Any One Care To Explain Why My Messages are Voted Down? Pin
ThatsAlok9-Jan-06 17:59
ThatsAlok9-Jan-06 17:59 
GeneralRe: how to pass a class ,object to a function by using pointers? Pin
Kevin McFarlane7-Jan-06 5:14
Kevin McFarlane7-Jan-06 5:14 
QuestionRe: how to pass a class ,object to a function by using pointers? Pin
David Crow7-Jan-06 17:17
David Crow7-Jan-06 17:17 
Questionlist iterator for all derived class (of a parent class) Pin
tbrake7-Jan-06 3:30
tbrake7-Jan-06 3:30 
QuestionIntegrating MFC application login with Windows login Pin
mohanrajh7-Jan-06 2:27
mohanrajh7-Jan-06 2:27 
AnswerRe: Integrating MFC application login with Windows login Pin
#realJSOP7-Jan-06 2:40
professional#realJSOP7-Jan-06 2:40 
If I understand correctly, you want the program to log the user in based on their current log-in status in Windows. Try this code:

Header file:
// QOSUser.h: interface for the CUser class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_USER_H__E9C9AE42_48F3_47E0_BA0C_ECA5F0DDD558__INCLUDED_)
#define AFX_USER_H__E9C9AE42_48F3_47E0_BA0C_ECA5F0DDD558__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CQOSUser  
{
public:
	CQOSUser();
	virtual ~CQOSUser();
	HRESULT GetUserInfo(CString & strLogonDomain, CString& strUserName, CString& strLogonServer);

};

#endif // !defined(AFX_USER_H__E9C9AE42_48F3_47E0_BA0C_ECA5F0DDD558__INCLUDED_)


CPP file:

// QOSUser.cpp: implementation of the CQOSUser class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "QOSUser.h"

// use pointy brackets on includes below (instead of quotes)
#include "windows.h"
#include "assert.h"
#include "lm.h"
#include "sstream"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CQOSUser::CQOSUser()
{

}

CQOSUser::~CQOSUser()
{

}

HRESULT CQOSUser::GetUserInfo(CString & strLogonDomain, CString& strUserName, CString& strLogonServer)
{
    HRESULT hResult = S_OK;
    WKSTA_USER_INFO_1* pUserInfo = 0;

    NET_API_STATUS status = ::NetWkstaUserGetInfo(0, // reserved
                                                  1, // level 1 returns WKSTA_USER_INFO_1
                                                  reinterpret_cast<PBYTE*>(&pUserInfo));

    // If successful return the logon info, otherwise return error info.

    if (NERR_Success == status)
    {
        ASSERT(0 != pUserInfo);

        strLogonDomain = reinterpret_cast<PCWSTR>(pUserInfo->wkui1_logon_domain);
        strUserName = reinterpret_cast<PCWSTR>(pUserInfo->wkui1_username);
        strLogonServer = reinterpret_cast<PCWSTR>(pUserInfo->wkui1_logon_server);

        status = ::NetApiBufferFree(pUserInfo);
        ASSERT(NERR_Success == status);
    }
    else
    {
        hResult = E_FAIL;
    }

    return hResult;
}


Usage:

CString  m_strUserDomain;
CString  m_strUserName;
CString  m_strUserServerLogin;
CQOSUser u;

u.GetUserInfo(m_strUserDomain, m_strUserName, m_strServerLogin);


------- sig starts

"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt

"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001



-- modified at 8:52 Saturday 7th January, 2006
GeneralRe: Integrating MFC application login with Windows login Pin
mohanrajh7-Jan-06 19:38
mohanrajh7-Jan-06 19:38 
GeneralRe: Integrating MFC application login with Windows login Pin
#realJSOP8-Jan-06 3:07
professional#realJSOP8-Jan-06 3:07 
AnswerRe: Integrating MFC application login with Windows login Pin
#realJSOP7-Jan-06 3:33
professional#realJSOP7-Jan-06 3:33 
AnswerRe: Integrating MFC application login with Windows login Pin
vipinasda7-Jan-06 9:03
vipinasda7-Jan-06 9:03 
AnswerRe: Integrating MFC application login with Windows login Pin
bob169727-Jan-06 16:10
bob169727-Jan-06 16:10 
QuestionListView ctrl with 1000's of images Pin
Jim Crafton7-Jan-06 0:57
Jim Crafton7-Jan-06 0:57 
AnswerRe: ListView ctrl with 1000's of images Pin
#realJSOP7-Jan-06 2:58
professional#realJSOP7-Jan-06 2:58 
AnswerRe: ListView ctrl with 1000's of images Pin
Gary R. Wheeler7-Jan-06 4:43
Gary R. Wheeler7-Jan-06 4:43 
AnswerRe: ListView ctrl with 1000's of images Pin
Joel Lucsy7-Jan-06 10:05
Joel Lucsy7-Jan-06 10:05 
QuestionHow to check if the share permission of some net share folder includes 'Full Control for Everyone'? Pin
wangdave6-Jan-06 22:15
wangdave6-Jan-06 22:15 
AnswerRe: How to check if the share permission of some net share folder includes 'Full Control for Everyone'? Pin
#realJSOP7-Jan-06 3:03
professional#realJSOP7-Jan-06 3:03 
GeneralRe: How to check if the share permission of some net share folder includes 'Full Control for Everyone'? Pin
PJ Arends7-Jan-06 14:31
professionalPJ Arends7-Jan-06 14:31 
AnswerRe: How to check if the share permission of some net share folder includes 'Full Control for Everyone'? Pin
Gary R. Wheeler7-Jan-06 13:50
Gary R. Wheeler7-Jan-06 13:50 
GeneralRe: How to check if the share permission of some net share folder includes 'Full Control for Everyone'? Pin
wangdave12-Jan-06 22:48
wangdave12-Jan-06 22:48 
QuestionSir, help me How to increment a value till i Hold Button? Pin
CodeVarma6-Jan-06 21:45
CodeVarma6-Jan-06 21:45 
AnswerRe: Sir, help me How to increment a value till i Hold Button? Pin
_anil_7-Jan-06 0:11
_anil_7-Jan-06 0:11 
AnswerRe: Sir, help me How to increment a value till i Hold Button? Pin
Michael Dunn7-Jan-06 8:19
sitebuilderMichael Dunn7-Jan-06 8:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.