【发布时间】:2015-09-13 21:18:41
【问题描述】:
我创建了一个简单的批处理脚本来使用以下代码对计算机进行伪锁定:
@ECHO OFF & setlocal ENABLEDELAYEDEXPANSION
setlocal EnableDelayedExpansion
color a
TITLE Lock
if not "%1" == "max" (
powershell -command "& { $x = New-Object -ComObject Shell.Application; $x.minimizeall() }"
start /MAX cmd /c %0 max & exit/b
)
:Lock
echo Please enter a password to lock your computer . . .
powershell -Command $pword = read-host "Enter password" -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > EOFlock.txt & set /p Pass1=<EOFlock.txt & del EOFlock.txt
TITLE Lock
taskkill /IM explorer.exe /F >nul
cls
echo Please type the password to unlock the computer . . .
:Locked
set /p Pass2=
:Unlock
if !Pass1! == !Pass2! (goto End)
goto Locked
:End
start explorer.exe
echo This Computer is unlocked.
我希望此窗口保持在顶部,并且最好在到达文件末尾之前不可关闭。但是,我还没有找到这样做的方法。
【问题讨论】:
-
实际上我不认为有纯批处理的方法...可能使用 VBScript 或 JavaScript...适合您,您应该编辑您的帖子并添加相应的标签...
-
关于 PowerShell 中的实现,您可能对 this post... 感兴趣。
-
与其“伪锁定”屏幕,不如实际lock the screen?
-
@Dennis,如果您还在寻找,您可能会发现 this answer 很有用。
标签: powershell batch-file