logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

윈도우에서 패스워드 입력 실패로 잠금 상태인지 확인 하는 방법

by lizard2019 posted Nov 05, 2024
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

먼저 로컬 보안 정책에서 계정 잠금 기간 값을 가져온다.

 

#include <windows.h>

#include <LM.h>

#include <iostream>

 

#pragma comment(lib, "netapi32.lib")

 

int main() {

    USER_MODALS_INFO_3* userModalsInfo;

    NET_API_STATUS status = NetUserModalsGet(NULL, 3, (LPBYTE*)&userModalsInfo);

 

    if (status == NERR_Success) {

        std::wcout << L"잠금 시간: " << userModalsInfo->usrmod3_lockout_duration / 60 << L"분" << std::endl;

        NetApiBufferFree(userModalsInfo);

    } else {

        std::cerr << "Error: " << status << std::endl;

    }

 

    return 0;

}

 
 
아래 코드로 윈도우 시스템 이벤트에서 잠금 이벤트 ID 4740을 검색한다.
 
#include <iostream>
#include <Windows.h>
#include <winevt.h>
 
#pragma comment(lib, "wevtapi.lib")
 
void QueryEventLog()
{
    // 열려는 로그의 이름 (Security 로그)
    LPCWSTR logName = L"Security";
    // 검색할 쿼리 - Event ID 4740
    LPCWSTR query = L"*[System[(EventID=4740)]]";
 
    EVT_HANDLE hResults = EvtQuery(nullptr, logName, query, EvtQueryReverseDirection | EvtQueryTolerateQueryErrors);
    if (!hResults) {
        std::cerr << "EvtQuery failed with error code: " << GetLastError() << std::endl;
        return;
    }
 
    EVT_HANDLE hEvent;
    DWORD dwReturned = 0;
    while (EvtNext(hResults, 1, &hEvent, INFINITE, 0, &dwReturned)) {
        DWORD dwBufferSize = 0;
        DWORD dwBufferUsed = 0;
        DWORD dwPropertyCount = 0;
        
        // 이벤트 텍스트 데이터를 읽기 위해 필요한 버퍼 크기를 확인
        EvtRender(nullptr, hEvent, EvtRenderEventXml, dwBufferSize, nullptr, &dwBufferUsed, &dwPropertyCount);
        
        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
            std::wstring buffer(dwBufferUsed / sizeof(wchar_t), L'\0');
            if (EvtRender(nullptr, hEvent, EvtRenderEventXml, dwBufferUsed, &buffer[0], &dwBufferUsed, &dwPropertyCount)) {
                // 이벤트 XML 출력
                std::wcout << L"Event: " << buffer << std::endl;
            }
        }
        
        EvtClose(hEvent);
    }
 
    if (GetLastError() != ERROR_NO_MORE_ITEMS) {
        std::cerr << "EvtNext failed with error code: " << GetLastError() << std::endl;
    }
 
    EvtClose(hResults);
}
 
int main()
{
    QueryEventLog();
    return 0;
}
 
검색후 마지막 이벤트 XML값에서 이벤트 시점과  잠금 기간을 더한 값을 현재 시간과 비교해서 이전이면 잠금 상태라고 판단한다.
물론 이벤트가 없으면 잠금 상태가 아니다.
 

  1. No Image 20Jan
    by lizard2019
    2025/01/20 by lizard2019
    Views 84 

    rmix test application 배포

  2. No Image 05Nov
    by lizard2019
    2024/11/05 by lizard2019
    Views 538 

    윈도우에서 패스워드 입력 실패로 잠금 상태인지 확인 하는 방법

  3. No Image 30Aug
    by digipine
    2024/08/30 by digipine
    Views 502 

    OpenSSL Build for Windows

  4. No Image 27Aug
    by digipine
    2024/08/27 by digipine
    Views 991 

    Rapid JSON 간단 사용법

  5. No Image 27Aug
    by digipine
    2024/08/27 by digipine
    Views 782 

    Direct X 11에서 그래픽 카드의 정보 가져오는 예제

  6. No Image 27Aug
    by digipine
    2024/08/27 by digipine
    Views 805 

    Python Slack 메시지 발송하는 예제

  7. No Image 27Aug
    by digipine
    2024/08/27 by digipine
    Views 614 

    Python email 보내는 예제 코드

  8. No Image 08Aug
    by digipine
    2024/08/08 by digipine
    Views 501 

    UDP 핀홀 트래버설 과정 요약, UDP pinhole traversal

  9. No Image 08Aug
    by digipine
    2024/08/08 by digipine
    Views 515 

    NAT 상태에서 P2P 통신하는 방법

  10. Windows Visual Studio 2022 OpenSSL Build 방법

  11. No Image 28Mar
    by digipine
    2024/03/28 by digipine
    Views 732 

    Visual Studio 단축키 정리

  12. 프로그래밍 언어 순위 2023년

  13. No Image 11Aug
    by digipine
    2023/08/11 by digipine
    Views 839 

    이벤트 텍소노미(Event Taxonomy)란 무엇인가요?

  14. Bitbucket에서 SSH 키 등록하고 사용하는 방법 (맥/리눅스)

  15. No Image 12May
    by digipine
    2023/05/12 by digipine
    Views 852 

    FFServer RTSP Audio Server Config

  16. No Image 15Feb
    by lizard2019
    2023/02/15 by lizard2019
    Views 867 

    OBS Studio for Http Interface EXE

  17. No Image 06Oct
    by digipine
    2022/10/06 by digipine
    Views 1496 

    xcode xib encountered an error communicating with ibagent-ios 해결

  18. No Image 25Sep
    by lizard2019
    2022/09/25 by lizard2019
    Views 1357 

    XCode 사용시 git ignore 로 xcuserstate 충돌 해결하기, .gitignore에 등록했는데도 동작안할때 해결방법

  19. No Image 05Sep
    by digipine
    2022/09/05 by digipine
    Views 1408 

    MAC Screen Sharing을 위한 VNC 접속을 위한 Port 변경 방법

  20. No Image 26Jan
    by digipine
    2022/01/26 by digipine
    Views 1679 

    Phabricator Ubuntu Installation Guide

Board Pagination Prev 1 2 3 4 5 6 Next
/ 6

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5