i had a work-free morning and were a bit bored. So I started coding this code, because blocking CTRL+ALT+DEL is asked often.
It is a combination of DLL injecting Functions and a source of a DLL to inject in winlogon.exe to disable CTRL+ALT+DEL.
I only tested on XP, If someone could test it on Vista....

The code was inspired by http://www.codeproject.com/win32/Antoni ... print=true
I ported some passages of it in this code.
Sorry for my bad English.

The functions:Functions
Inject(PID,DLLPath.s) -> Inject DLL, Important: Full path!
Eject(PID,hLibModule) -> Eject DLL, hLibModule is returned by Inject
GetPIDFromName(Name.s) -> Get PID of an EXE
DebugPrevileg(Bool) -> #True = Debug Previleg on, is needed for injecting in SYSTEM apps. This function is used by Inject and Eject automatically
Code: Select all
EnableExplicit
Procedure GetPIDFromName(Name.s)
Define hSnapshot.l, ProcessInfo.PROCESSENTRY32, Retval.l, PID.l
hSnapshot = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)
ProcessInfo\dwSize = SizeOf(ProcessInfo)
Retval = Process32First_(hSnapshot,@ProcessInfo)
While Retval
If PeekS(@ProcessInfo\szExeFile) = Name
PID=PeekL(@ProcessInfo\th32ProcessID)
Break
Else
Retval = Process32Next_(hSnapshot,@ProcessInfo)
EndIf
Wend
ProcedureReturn PID
EndProcedure
Procedure DebugPrevileg(Flag)
Define tk.TOKEN_PRIVILEGES, hToken.l
OpenProcessToken_(GetCurrentProcess_(),#TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY | #TOKEN_READ, @hToken)
LookupPrivilegeValue_(0,"SeDebugPrivilege",tk\Privileges\Luid)
tk\PrivilegeCount = 1
If Flag = #True
tk\Privileges\Attributes = #SE_PRIVILEGE_ENABLED
Else
tk\Privileges\Attributes = 0
EndIf
AdjustTokenPrivileges_(hToken,0,tk,0,0,0)
EndProcedure
Procedure Inject(PID,DLLPath.s)
Define hThread.l, hProcess.l,pLibRemote.l,hLibModule.l
DebugPrevileg(#True)
hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, #False, PID)
pLibRemote = VirtualAllocEx_(hProcess, #Null, 255, #MEM_COMMIT, #PAGE_READWRITE)
WriteProcessMemory_(hProcess, pLibRemote, DLLPath, 255, #Null)
hThread = CreateRemoteThread_(hProcess,#Null,0,GetProcAddress_(GetModuleHandle_("Kernel32"), "LoadLibraryA"),pLibRemote,0,#Null)
WaitForSingleObject_(hThread, #INFINITE)
GetExitCodeThread_(hThread, @hLibModule)
CloseHandle_(hThread)
CloseHandle_(hProcess)
VirtualFreeEx_(hProcess, pLibRemote, SizeOf(DLLPath), #MEM_RELEASE)
DebugPrevileg(#False)
ProcedureReturn hLibModule
EndProcedure
Procedure Eject(PID,hLibModule.l)
Define hThread.l, hProcess.l
DebugPrevileg(#True)
hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, #False, PID)
hThread = CreateRemoteThread_(hProcess,#Null,0,GetProcAddress_(GetModuleHandle_("Kernel32"), "FreeLibrary"),hLibModule,0,#Null)
WaitForSingleObject_(hThread, #INFINITE)
CloseHandle_(hThread)
CloseHandle_(hProcess)
DebugPrevileg(#False)
EndProcedure
Code: Select all
Global hSASWnd.l,OldSASProc.l
ProcedureDLL MakeLong(low,high)
ProcedureReturn low + (high << 16)
EndProcedure
ProcedureDLL SASWindowProc(hWnd,uMsg,wParam,lParam)
If uMsg = #WM_HOTKEY
If lParam = MakeLong(#MOD_CONTROL | #MOD_ALT, #VK_DELETE)
ProcedureReturn 1
EndIf
EndIf
ProcedureReturn CallWindowProc_(OldSASProc, hWnd, uMsg, wParam, lParam)
EndProcedure
ProcedureDLL AttachProcess(hInstance)
hSASWnd = FindWindow_("SAS Window class","SAS window")
OldSASProc = SetWindowLong_(hSASWnd, #GWL_WNDPROC, @SASWindowProc())
EndProcedure
ProcedureDLL DetachProcess(hInstance)
SetWindowLong_(hSASWnd, #GWL_WNDPROC, OldSASProc)
EndProcedure
Code: Select all
Define hLibModule.l,PID.l
PID=GetPidFromName("winlogon.exe")
hLibModule=Inject(PID,<Put full path of the DLL here>)
Delay(10000)
Eject(PID,hLibModule)
125