【问题标题】:Always on top batch script始终在顶部批处理脚本
【发布时间】: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


【解决方案1】:

您可以调用 PowerShell,而后者又可以调用 WinAPI... 至少在 Windows 8+ 上(7 可能也可以工作,以前的版本可能不行)。

比较简单:

  1. 调用 PowerShell
  2. 让它独立于上下文运行
  3. 使用SetWindowPos 将窗口置于前面
  4. 使用GetConsoleWindow 找出要操作的窗口

这一切都非常适合一个命令:

@powershell -ExecutionPolicy UnRestricted -Command "(Add-Type -memberDefinition \"[DllImport(\"\"user32.dll\"\")] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x,int y,int cx, int xy, uint flagsw);\" -name \"Win32SetWindowPos\" -passThru )::SetWindowPos((Add-Type -memberDefinition \"[DllImport(\"\"Kernel32.dll\"\")] public static extern IntPtr GetConsoleWindow();\" -name \"Win32GetConsoleWindow\" -passThru )::GetConsoleWindow(),-1,0,0,0,0,67)"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 2015-05-08
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    相关资源
    最近更新 更多