Question

Okay, so I have a lock script that locks my computer, but using alt + tab gets around this. Is there a way to stop this? Also, entering nothing and pressing enter gets around it too.

The code uses 2 windows, one to keep the window open when it is closed

@echo off
powershell -command "& { $x = New-Object -ComObject Shell.Application; $x.minimizeall() }"
tskill explorer
tskill explorer
:a
start /w Lock.bat
goto a

and the other is the actual lock script:

@echo off
mode 35,10
cls
color a
title Locked by %username%
echo What is the password?
set /p password=
if %password%==password goto end
goto fail

:end
start explorer
exit

:fail
exit

Is there a way to stop these from happening?

Edit

I solved the blank issue by using

If [%password%]==[] goto fail
Was it helpful?

Solution

Although I dont know how to stop the spawning of the explorer process with the behavior outlined above, but here is a the kill wa

Main script:

@echo off
powershell -command "& { $x = New-Object -ComObject Shell.Application; $x.minimizeall() }"
start /min kill_switch.bat
:a
start /w Lock.bat
goto a

Lock.bat:

@echo off
mode 35,10
cls
color a
title Locked by %username%
echo What is the password?
set /p password=
if %password%==password goto end
goto fail

:end
echo "start explorer">"%TEMP%\startex.trace"
exit

:fail
exit

kill_switch.bat:

@echo off

if exist "%TEMP%\startex.trace" del /q "%TEMP%\startex.trace"

:KILL_SWITCH
for /f "skip=2 tokens=2 delims= " %%a in ('tasklist /FI "IMAGENAME eq explorer.exe"') do (
    echo INFO: Killing PID %%a
    taskkill /PID %%a /F
)

timeout /t 5 >nul
if not exist "%TEMP%\startex.trace" (
    goto KILL_SWITCH
) else (
    del /q "%TEMP%\startex.trace"
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top