如何制作休眠批处理文件?

发布于 2024-12-13 09:05:15 字数 217 浏览 6 评论 0原文

我正在尝试制作一个执行简单命令的批处理文件:

shutdown -h

我创建了一个 shutdown.bat 文件,其中包含该行,但是当我运行它时,它所做的只是垃圾邮件命令提示符就像疯了一样。

我查看过批处理文件站点,@echo off 似乎很受欢迎,但这不是在执行命令时隐藏输出吗?

I'm trying to make a batch file that executes a simple command:

shutdown -h

I've created a shutdown.bat file with that exact line in it, yet when I run it, all it does is spam the command prompt like crazy.

I've looked at batch file sites, @echo off seems popular, but doesn't that just hide output while the commands are executed just the same?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乖乖兔^ω^ 2024-12-20 09:05:15

事实证明,将更改目录命令添加到驱动器的根目录可以解决问题。我最终在 .bat 文件中使用的最终文本是:

cd c:\
shutdown /h

It turns out that adding a change directory command to the root of the drive fixes the problem. The final text that I ended up using in the .bat file was:

cd c:\
shutdown /h
情绪少女 2024-12-20 09:05:15

我相信我已经很晚了,但以防万一其他人遇到这个问题。
问题确实出在bat文件的名称上。您正在调用 shutdown -h 并且该 bat 文件名为 shutdown.bat,因此该 bat 文件正在调用自身,从而导致命令提示符循环。要解决此问题,您可以重命名 bat 文件或指定 shutdown 所在的目录。

I believe I am very late for this but just in case someone else comes across this.
The issue was indeed with the name of the bat file. You were calling shutdown -h and the bat file was called shutdown.bat hence the bat file was calling itself causing the loop of the command prompts. To fix this you either rename the bat file or specify the directory where shutdown is located.

习ぎ惯性依靠 2024-12-20 09:05:15

很想说我明白了这一点,但我只是用谷歌搜索了一下。
你需要的代码是

%windir%System32rundll32.exe powrprof.dll,SetSuspendState

如果你去开始->;运行然后输入它应该可以工作。
因此,如果您在电源选项中启用了休眠功能,这也应该在批处理文件中起作用。

希望这对您有帮助

编辑:
Ps 单击箭头下方的白色小 V(此答案的左侧)接受答案;)

Would love to say I figured this out but I simply googled it.
The code you need is

%windir%System32rundll32.exe powrprof.dll,SetSuspendState

If you go to start -> run and then type this in it should work.
So if you have hibernate enabled in the poweroptions this should also work in a batch file.

Hope this helped you

Edit:
P.s. click the white little V under the arrows (left of this answer) to accept the answer ;)

与他有关 2024-12-20 09:05:15

对于关闭:(

c:\windows\system32\shutdown -s -f -t 00

或执行 ...shutdown -p -f)。

例如:设置时间-t 1000并保存并运行。

仅中止不同批处理文件中的c:\windows\system32\shutdown -a

需要注意的非常重要的一点:如果您在启动中找到此批处理文件,那么它将立即执行s/h/r。例如,您创建一个注销批处理文件,然后在启动中找到它
它将在给定时间内/立即注销电脑。但是,当您在登录时按住 Shift 键时,它将中止注销批处理文件,否则您的电脑将一次又一次注销。你不必这样做,我不确定它是否适用于每台电脑。

创建一个用户并尝试一下,以防您无法登录。祝你好运

对于重新启动:

c:\windows\system32\shutdown -r -t 00

对于休眠:

c:\windows\system32\shutdown /h

参考:https://www.instructables.com/id/Shutdown-restart-or-hibernate-your-computer-on-a/

For shutdown:

c:\windows\system32\shutdown -s -f -t 00

(or do ...shutdown -p -f).

E.g.: set the time -t 1000 and save and run it.

To abort just c:\windows\system32\shutdown -a in different batch file.

Very important point to note: if you locate this batch file in your startup then it will execute the s/h/r immediately. E.g. you create a logoff batch file and you locate it in startup
it will logoff the pc within the given time/immediately. However, when you hold shift when logging then it will abort the logoff batch file otherwise you pc will logoff again and again. You don't have to do this I am not sure if it works on every PC.

Create a user and try it there in case you could not log in. good luck

For restart:

c:\windows\system32\shutdown -r -t 00

For hibernate:

c:\windows\system32\shutdown /h

Reference: https://www.instructables.com/id/Shutdown-restart-or-hibernate-your-computer-on-a/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文