如何使用实际会自行关闭的BAT脚本关闭屏幕 [英] How to Shut Off Screen with BAT Script that Actually Closes Itself Afterwards

查看:120
本文介绍了如何使用实际会自行关闭的BAT脚本关闭屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现此脚本关闭了我的计算机屏幕:

I found this script to shut off my computer screen:

powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)

该脚本除了无法自动关闭外,还存在问题,&阻止f.lux在我移动光标以重新打开屏幕后关闭控制台之前无法正常工作,我发现此脚本需要使用Windows PowerShell的事实似乎过分了.

In addition to this script being problematic in that it doesn't automatically close, & prevents f.lux from working before I close the console upon moving my cursor to turn my screen back on, I find the fact that this script needs to use Windows PowerShell seems like overkill.

因此,这可能是一个愚蠢的请求,但我希望有人知道一种无需使用关闭屏幕和屏幕的PowerShell即可运行批处理脚本的方法.自动关闭.

So, this may be a stupid request, but I'm hoping someone knows a way to run a batch script without the use of PowerShell that turns off the screen & automatically closes.

以下是我尝试过的一些命令(及其结果):

Here are some of the commands I've tried (and their results):

此命令(以 -NoLogo -NoProfile -Command 的任意组合结尾或不结尾)将关闭屏幕,但导致空白的Powershell窗口保持打开状态:

This command (with any combination of -NoLogo, -NoProfile, and -Command either at the end or not) shuts off the screen, but causes a blank powershell window to stay open:

start powershell -NoLogo -NoProfile -Command (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)

此命令(带有或不带有对powershell.exe的特定引用,在其前面带有或不带有空引号,在 start 之前带有或不带有 @ 符号,&以及 -NoLogo -NoProfile -Command 的任意组合(无论是否结尾)都不会关闭屏幕,并导致下面的Powershell窗口(由于我的 -NoExit 命令而一直保持打开状态):

This command (with or without the specific reference to powershell.exe, with or without the empty quotation marks before it, with or without an @ symbol before start, & with any combination of -NoLogo, -NoProfile, and -Command either at the end or not) doesn't shut off the screen, and causes the powershell window below (which only stays open due to my -NoExit command):

start "" "%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoExit -NoLogo -NoProfile -Command "(Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)"

输入该命令后唯一发生变化的是在此powershell窗口中引用的临时文件:

The only thing that changes with the entering of that command is the temporary file referenced in this powershell window:

推荐答案

我的假设是您找到的命令未加双引号,因此需要转义字符 ^ 才能起作用.根据我以前的建议,将命令括在双引号中,以下是我的建议,即.删除插入符号:

My assumption is that the command you found was not doublequoted and therefore required an escape character, ^, to function. Based upon my previous advice, of enclosing the command within doublequotes, the following is my suggestion, i.e. removing the caret:

@Start "" "%__AppDir__%WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -Command "(Add-Type '[DllImport(\"user32.dll\")]public static extern int SendMessage(int hWnd,int hMsg,int wParam,int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)"

这篇关于如何使用实际会自行关闭的BAT脚本关闭屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆