简体   繁体   English

完成后无法批量注销

[英]Can't get batch to logout when it's done

I have a .bat that I've wrote to automate an install of a piece of software I have to install all the time at work. 我已经编写了一个.bat来自动安装我必须在工作中一直安装的软件。 (I can't use powershell because a lot of the machines are XP still) (我不能使用powershell,因为很多机器仍然是XP)

Near the end, the script is supposed to clean itself up and and logout, but I can't get it to log out for some reason. 脚本快要结束了,应该清理并注销,但是由于某种原因我无法注销。

taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
wait 2
shutdown -f -l

There is no wait command in CMD. CMD中没有wait命令。 There is timeout for Win7+ but not for XP. Win7 +有timeout ,但XP没有timeout To implement a kind of a timeout you'll have to use for example ping 127.0.0.1 -n 6 > nul . 要实现某种超时,您必须使用例如ping 127.0.0.1 -n 6 > nul This will make your system "wait" for 5 seconds. 这将使系统“等待” 5秒钟。 You can modify the timeout by replacing 6 with any other value. 您可以通过将6替换为其他任何值来修改超时。 If you want a timeout of X seconds, replace 6 with X+1. 如果要X超时,请用X + 1替换6。

EDIT: Made a stupid mistake making this, fixed it up. 编辑:犯了一个愚蠢的错误,将其修复。

Try this instead: 尝试以下方法:

taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
pause
shutdown -f -l

All I did was make it so that the wait is replaced with pause 我所做的就是做到这一点,以便将wait替换为pause

I did some looking around, and I couldn't find any native commands that make the batch file delay and automatically continue, so this is the closest I can find. 我四处张望,找不到任何使批处理文件延迟并自动继续的本机命令,因此这是我能找到的最接近的命令。 (Assuming the computer you're using this on is a Windows XP) (假设您使用的计算机是Windows XP)

If you don't use a Windows XP for the batch file, use this instead: 如果您不使用Windows XP作为批处理文件,请改用以下方法:

taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
timeout /t 2 >nul
shutdown -f -l

The timeout acts as a delay, however, it is unfortunately not a native command on Windows XP, but it is on Windows 7+ (Unsure about vista) Hope this helps :) timeout是一个延迟,但是,不幸的是,它不是Windows XP上的本机命令,但是在Windows 7+上(不确定vista),希望对您有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在完成工作后关闭批处理文件的 cmd 窗口? - How to get a batch file's cmd window to close after it's done its job? 手动完成后,批处理文件将成功执行SSIS包,但使用Windows Task Scheduler执行该批处理文件时将失败 - Batch file executes SSIS package successfully when done manually, but fails when it's executed with Windows Task Scheduler 为什么批处理脚本完成后,我的shell实例为什么不终止? - Why doesn't my shell instance terminate when done with the batch script? 完成后自动关闭批处理文件 - automatically close batch file when done 何时批量IF比较操作以数字方式完成 - when is batch IF compare-op done numerically 无法找出导致此批处理脚本错误的原因 - Can't figure out what's causing the error in this batch script 批处理脚本无法将变量的内容传递给其他变量 - Batch script can't pass variable's contents to other variables 在Seam中运行长时间批处理作业时获取服务器注销 - Getting server logout when running long batch jobs in Seam Windows 7 无法获取批处理文件以正确复制内容 - Windows 7 Can't get Batch file to copy things properly 无法从批处理脚本中的失败MOVE命令获取错误级别 - Can't get errorlevel from failed MOVE command in batch script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM