Created
February 23, 2012 12:07
-
-
Save grawity/1892562 to your computer and use it in GitHub Desktop.
Workstation unlocker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#define WIN32_LEAN_AND_MEAN | |
#include "targetver.h" | |
#include <stdio.h> | |
#include <tchar.h> | |
#include <windows.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#define WM_LOGONNOTIFY 0x004c | |
#define LN_UNLOCK_WORKSTATION 0x0006 | |
void showError() | |
{ | |
LPTSTR pBuf; | |
DWORD nBytes = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, | |
NULL, GetLastError(), LANG_USER_DEFAULT, (LPWSTR)&pBuf, 4096, NULL); | |
if (nBytes) | |
wprintf(L"Error: %s", pBuf); | |
else | |
wprintf(L"Failed to format error message: %08x\n", GetLastError()); | |
} | |
BOOL CALLBACK enumWndProc(HWND hWnd, HWND *hSasWindow) | |
{ | |
LPTSTR lpClassName[64]; | |
if (!GetClassName(hWnd, (LPTSTR)&lpClassName, 63)) | |
return TRUE; | |
if (wcscmp((LPTSTR)lpClassName, L"SAS window class") != 0) | |
return TRUE; | |
*hSasWindow = hWnd; | |
return FALSE; | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
HDESK hDesktop = NULL; | |
HWND hSasWindow = NULL; | |
hDesktop = OpenDesktop(L"Winlogon", 0, FALSE, DESKTOP_READOBJECTS | DESKTOP_ENUMERATE); | |
if (!hDesktop) { | |
showError(); | |
return 1; | |
} | |
EnumDesktopWindows(hDesktop, (WNDENUMPROC)enumWndProc, (LPARAM)&hSasWindow); | |
if (!hSasWindow) { | |
wprintf(L"Error: WinLogon window not found.\n"); | |
return 1; | |
} | |
PostMessage(hSasWindow, WM_LOGONNOTIFY, LN_UNLOCK_WORKSTATION, 0); | |
wprintf(L"Success: Unlock message sent to %p\n", hSasWindow); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works on Windows XP when run with some
psexec
magic (tell psexec to run it on the secure logon desktop).