June 16, 2024, 08:01:44 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Disable / Enable Alt + Tab function

Started by Andy, April 20, 2011, 11:12:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

I am trying to find a way to disable / enable the Alt + Tab function

Basically, I have a password screen and I don't want a user to use the Alt + Tab function to bypass this screen and tab to another screen. 

I want to disable the ALt + Tab function here, but after the user either enters a password or closes the screen then I would like the ALt + Tab function to be re-enabled

There is a way in XP, it's a registry settings called 'CoolSwitching' but it doesn't work in Vista or Win 7

Can anyone help please ?

Happy Easter,
Andy.




Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

sapero

April 21, 2011, 12:51:53 AM #1 Last Edit: April 21, 2011, 12:53:35 AM by sapero
Andy, try switching desktop to a custom one, like winlogon does:
$include "windowssdk.inc"
'$include "stdafx.inc"

' example usage
RunInSecureDesktop(0, &MySecureFunction, 0, 20000/*INFINITE*/)

' another example
$if 0
UINT function_result
if (!RunInSecureDesktop(0, &MySecureFunction, 0, 20000/*INFINITE*/, &function_result))
' failure
else
print function_result
endif
$endif

' a function running on separate desktop, in separate thread
sub MySecureFunction(pointer parameter),uint
' please do not crash here
' to do: open login window here, use WAITUNTIL ...
MESSAGEBOX 0, "Check what ALT+TAB does", "on secure desktop"
return 0
endsub

'==================================================

sub RunInSecureDesktop(int reserved, LPTHREAD_START_ROUTINE function, pointer parameter, DWORD dwTimeout,opt pointer pResult),BOOL
BOOL result = FALSE
HDESK hCurrentDesktop = GetThreadDesktop(GetCurrentThreadId())
HDESK hSecureDesktop = CreateDesktop(T"MyAppLoginDesktop",NULL,NULL,0/*DF_ALLOWOTHERACCOUNTHOOK*/,GENERIC_ALL,NULL)
if (hSecureDesktop)
DWORD dwThreadId
reserved = static_cast(int, hSecureDesktop)
HANDLE hThread = CreateThread(0,0,&ThreadLauncher,&reserved,CREATE_SUSPENDED,&dwThreadId)
if (hThread)
'SwitchDesktop(hSecureDesktop) ' error: SetThreadDesktop must be called first
ResumeThread(hThread)
DWORD dwWaitResult = WaitForSingleObject(hThread, dwTimeout)
result = !dwWaitResult
if (dwWaitResult == WAIT_TIMEOUT)
TerminateThread(hThread, 1)
endif
' switch desktop to
SwitchDesktop(hCurrentDesktop)
CloseHandle(hThread)
endif
CloseDesktop(hSecureDesktop)
endif
return result
endsub


type MYDATA
HDESK hSecureDesktop
LPTHREAD_START_ROUTINE function
pointer parameter
DWORD   dwTimeout
pointer pResult
endtype

declare THFN(pointer parameter),uint

sub ThreadLauncher(MYDATA d ByRef),uint
UINT result=1
SetThreadDesktop(d.hSecureDesktop)
SwitchDesktop(d.hSecureDesktop)
try
UINT fn = d.function
result = !<THFN>fn(d.parameter)
endtry

if (d.pResult) then d.*<uint>pResult = result
return result
endsub

Andy

Thanks sapero,

will give it a go many thanks.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.