Powershell 始终在顶部的批处理脚本

Powershell 始终在顶部的批处理脚本,powershell,batch-file,Powershell,Batch File,我使用以下代码创建了一个简单的批处理脚本来伪锁计算机: @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

我使用以下代码创建了一个简单的批处理脚本来伪锁计算机:

@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.
@ECHO OFF&setlocal ENABLEDELAYEDEXPANSION
setlocal EnableDelayedExpansion
颜色a
所有权锁
如果不是“%1”=“最大值”(
powershell-命令“&{$x=New Object-ComObject Shell.Application;$x.minimizeall()}”
开始/最大命令/c%0最大和退出/b
)
:锁
echo请输入密码以锁定您的计算机。
powershell-命令$pword=读取主机“输入密码”-AsSecureString$BSTR=[System.Runtime.InteropServices.Marshall]::SecureStringToBSTR($pword);[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)>EOFlock.txt&set/ppass1=nul
cls
echo请键入密码以解锁计算机。
:锁定
设置/p密码2=
:解锁
如果!Pass1!==!Pass2!(转完)
转到锁定状态
:结束
启动explorer.exe
这台计算机已解锁。

我希望此窗口保持在顶部,最好在到达文件末尾之前不可关闭。但是,我还没有找到这样做的方法。

您可以调用PowerShell,而PowerShell又可以调用WinAPI。。。至少在Windows8+上是这样(7也可以,以前的版本可能不行)

这相对简单:

  • 呼叫PowerShell
  • 告诉它独立于上下文运行
  • 使用
    SetWindowPos
    将窗口置于前面
  • 使用
    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)"
    

    您可以调用PowerShell,而PowerShell又可以调用WinAPI。。。至少在Windows8+上是这样(7也可以,以前的版本可能不行)

    这相对简单:

  • 呼叫PowerShell
  • 告诉它独立于上下文运行
  • 使用
    SetWindowPos
    将窗口置于前面
  • 使用
    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)"
    

    您可以调用PowerShell,而PowerShell又可以调用WinAPI。。。至少在Windows8+上是这样(7也可以,以前的版本可能不行)

    这相对简单:

  • 呼叫PowerShell
  • 告诉它独立于上下文运行
  • 使用
    SetWindowPos
    将窗口置于前面
  • 使用
    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)"
    

    您可以调用PowerShell,而PowerShell又可以调用WinAPI。。。至少在Windows8+上是这样(7也可以,以前的版本可能不行)

    这相对简单:

  • 呼叫PowerShell
  • 告诉它独立于上下文运行
  • 使用
    SetWindowPos
    将窗口置于前面
  • 使用
    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)"
    

    事实上,我不认为有一种方法在纯批量。。。使用VBScript或JavaScript可能是可行的。。。如果这样对你合适,你应该编辑你的帖子并添加相应的标签…关于PowerShell中的一个实现,你可能会感兴趣…而不是“伪锁”屏幕,你为什么不呢?@Dennis如果你还在看的话,你可能会发现有用。事实上,我不认为在纯批处理中有方法。。。使用VBScript或JavaScript可能是可行的。。。如果这样对你合适,你应该编辑你的帖子并添加相应的标签…关于PowerShell中的一个实现,你可能会感兴趣…而不是“伪锁”屏幕,你为什么不呢?@Dennis如果你还在看的话,你可能会发现有用。事实上,我不认为在纯批处理中有方法。。。使用VBScript或JavaScript可能是可行的。。。如果这样对你合适,你应该编辑你的帖子并添加相应的标签…关于PowerShell中的一个实现,你可能会感兴趣…而不是“伪锁”屏幕,你为什么不呢?@Dennis如果你还在看的话,你可能会发现有用。事实上,我不认为在纯批处理中有方法。。。使用VBScript或JavaScript可能是可行的。。。如果这样对你合适,你应该编辑你的帖子并添加相应的标签…关于PowerShell中的一个实现,你可能会感兴趣…而不是“伪锁定”屏幕,你为什么不呢?@Dennis如果你还在寻找,你可能会觉得有用。