티스토리 뷰

개발/윈도우

로그인 계정 권한 확인

-=HaeJuK=- 2015. 6. 15. 18:18
728x90

로그인 계정의 권한 확인

Windows Os에서 현재 로그인중인 사용자의 권한 레벨을 확인해 봅시다. 

Haeder File

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
/******************************************************************************
* _    _                 _       _  __  _____               _           _     
*| |  | |               | |     | |/ / |  __ \             | |         | |    
*| |__| | __ _  ___     | |_   _| ' /  | |  | | _____   __ | |     __ _| |__  
*|  __  |/ _` |/ _ \_   | | | | |  <   | |  | |/ _ \ \ / / | |    / _` | '_ \ 
*| |  | | (_| |  __/ |__| | |_| | . \  | |__| |  __/\ V /  | |___| (_| | |_) |
*|_|  |_|\__,_|\___|\____/ \__,_|_|\_\ |_____/ \___| \_(_) |______\__,_|_.__/ 
*
* Copyright (c) HaeJuK Dev Lab All Rights Reserved.
*
*******************************************************************************/                                                                             
/**
@file        GetUserInfo.h
@brief
@author      Woolim Choi
@date        Create 2017.10.25
@ntoe        로그인된 사용자의 권한을 확인한다.
*/
 
#pragma once
 
#include  <lmaccess.h>
 
const DWORD cDwNetWLevel     = 1 ; 
const DWORD cDwNetUserLevel  = 2 ; 
 
class CGetUserInfo
{
public:
    enum USER_PRIV
    {
        eUSER_PRIV_GUEST = 0,
        eUSER_PRIV_USER,
        eUSER_PRIV_ADMIN,
    };
    
public:
    static CGetUserInfo &Instance();
    USER_PRIV GetUserType();
 
private:
    BOOL GetUserDomainInfo(LPUSER_INFO_2& pUserInfo);
 
private:
    CGetUserInfo(void);
    ~CGetUserInfo(void);
    CGetUserInfo& operator=(const CGetUserInfo&);
 
};
 
 
cs

 

Source File

sssssssssssssss
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/******************************************************************************
* _    _                 _       _  __  _____               _           _     
*| |  | |               | |     | |/ / |  __ \             | |         | |    
*| |__| | __ _  ___     | |_   _| ' /  | |  | | _____   __ | |     __ _| |__  
*|  __  |/ _` |/ _ \_   | | | | |  <   | |  | |/ _ \ \ / / | |    / _` | '_ \ 
*| |  | | (_| |  __/ |__| | |_| | . \  | |__| |  __/\ V /  | |___| (_| | |_) |
*|_|  |_|\__,_|\___|\____/ \__,_|_|\_\ |_____/ \___| \_(_) |______\__,_|_.__/ 
*
* Copyright (c) HaeJuK Dev Lab All Rights Reserved.
*
*******************************************************************************/                                                                             
/**
@file        GetUserInfo.cpp
@brief
 
@author      Woolim Choi
@date        Create 2017.10.25
@ntoe        로그인된 사용자의 권한을 확인한다.
*/
 
#include "StdAfx.h"
#include "GetUserInfo.h"
#include  <lmwksta.h>
#include  <lmerr.h>
#include  <lm.h>
#pragma comment(lib, "netapi32.lib")
#define RETURN(x,y){x=y;goto Exit;}
 
CGetUserInfo::CGetUserInfo(void)
{
}
 
CGetUserInfo::~CGetUserInfo(void)
{
}
 
CGetUserInfo& CGetUserInfo::Instance()
{
    static CGetUserInfo _Ins;
    return _Ins;
}
 
CGetUserInfo::USER_PRIV CGetUserInfo::GetUserType()
{
    CGetUserInfo::USER_PRIV result = eUSER_PRIV_ADMIN; 
 
    LPUSER_INFO_2 pUserInfo = NULL;
 
    if( FALSE == GetUserDomainInfo(pUserInfo) )
    {
        RETURN(result,eUSER_PRIV_ADMIN);
    }
    if(pUserInfo->usri2_priv == USER_PRIV_GUEST)
    {
        RETURN(result,eUSER_PRIV_GUEST);
    }
    else if(pUserInfo->usri2_priv == USER_PRIV_USER)
    {
        RETURN(result,eUSER_PRIV_USER);
    }
    else if(pUserInfo->usri2_priv == USER_PRIV_ADMIN)
    {
        RETURN(result,eUSER_PRIV_ADMIN);
    }
Exit:
    return result;
}
 
BOOL CGetUserInfo::GetUserDomainInfo(LPUSER_INFO_2& pUserInfo)
{
    BOOL bResult = TRUE;
 
    LPWKSTA_USER_INFO_1 pWkstaInfo = NULL;
    NET_API_STATUS nStatus = NetWkstaUserGetInfo(NULL,    cDwNetWLevel, (LPBYTE *)&pWkstaInfo);
    if (nStatus != NERR_Success || NULL == pWkstaInfo )
    {
        RETURN(bResult, FALSE);        
    }
 
    nStatus = NetUserGetInfo( (LPCWSTR)pWkstaInfo->wkui1_logon_server , 
                              (LPCWSTR)pWkstaInfo->wkui1_username, 
                              cDwNetUserLevel, 
                              (LPBYTE*)&pUserInfo);
    ifNULL == pUserInfo)
    {
        RETURN(bResult, FALSE);        
    }
 
Exit:
    if ( pWkstaInfo != NULL )
    {
        NetApiBufferFree(pWkstaInfo);
    }
    return bResult;
}
 
cs

 

사용법

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
/******************************************************************************
* _    _                 _       _  __  _____               _           _     
*| |  | |               | |     | |/ / |  __ \             | |         | |    
*| |__| | __ _  ___     | |_   _| ' /  | |  | | _____   __ | |     __ _| |__  
*|  __  |/ _` |/ _ \_   | | | | |  <   | |  | |/ _ \ \ / / | |    / _` | '_ \ 
*| |  | | (_| |  __/ |__| | |_| | . \  | |__| |  __/\ V /  | |___| (_| | |_) |
*|_|  |_|\__,_|\___|\____/ \__,_|_|\_\ |_____/ \___| \_(_) |______\__,_|_.__/ 
*
* Copyright (c) HaeJuK Dev Lab All Rights Reserved.
*
*******************************************************************************/                                                                             
/**
@file        main.cpp
@brief
@author      Woolim Choi
@date        Create 2017.10.25
@ntoe        로그인된 사용자의 권한을 확인한다.
*/
 
#include "stdafx.h"
#include <windows.h>
#include "GetUserInfo.h"
 
int main()
{
    CGetUserInfo::Instance().GetUserType();
    system("pause");
    return 0;
}
 
 
cs
반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/11   »
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
글 보관함
250x250