基本上我们有2个批处理文件,如果你愿意,它们就是“包装器”,调用另一个批处理文件,使其以/min
(最小化)开始。此批处理文件在启动第二个批处理文件后结束。
这包含一个循环,它在关闭后继续产生RDP会话。
问题是,如果用户ALT-TAB并关闭批处理,他们只剩下一个空桌面(因为我们任务杀死资源管理器)。如果批量循环结束,有没有办法强制重启机器?
谢谢!
答案 0 :(得分:0)
有一个标准的cmd命令:
shutdown /r
Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e | /o] [/hybrid] [/f] [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]] No args Display help. This is the same as typing /?. /? Display help. This is the same as not typing any options. /i Display the graphical user interface (GUI). This must be the first option. /l Log off. This cannot be used with /m or /d options. /s Shutdown the computer. /r Full shutdown and restart the computer. /g Full shutdown and restart the computer. After the system is rebooted, restart any registered applications. /a Abort a system shutdown. This can only be used during the time-out period. /p Turn off the local computer with no time-out or warning. Can be used with /d and /f options. /h Hibernate the local computer. Can be used with the /f option. /hybrid Performs a shutdown of the computer and prepares it for fast startup. Must be used with /s option. /e Document the reason for an unexpected shutdown of a computer. /o Go to the advanced boot options menu and restart the computer. Must be used with /r option. /m \\computer Specify the target computer. /t xxx Set the time-out period before shutdown to xxx seconds. The valid range is 0-315360000 (10 years), with a default of 30. If the timeout period is greater than 0, the /f parameter is implied. /c "comment" Comment on the reason for the restart or shutdown. Maximum of 512 characters allowed. /f Force running applications to close without forewarning users. The /f parameter is implied when a value greater than 0 is specified for the /t parameter. /d [p|u:]xx:yy Provide the reason for the restart or shutdown. p indicates that the restart or shutdown is planned. u indicates that the reason is user defined. If neither p nor u is specified the restart or shutdown is unplanned. xx is the major reason number (positive integer less than 256). yy is the minor reason number (positive integer less than 65536).
答案 1 :(得分:0)
我的建议:
你真的需要批量可见(最小化)还是可以隐藏?
如果可以隐藏它,只需使用VBScript将其隐藏起来:
With CreateObject("W"&"Script.Shell")
.Run "LongRun.bat", 0
End With
如果您确实需要显示批处理,可以创建一个隐藏的脚本,等待批处理终止并重新启动。
第1步:启动隐藏的脚本(Start.vbs
):
Set WsShell = CreateObject("W"&"Script.Shell")
WsShell.Run "Hidden.vbs", 0
第2步:Hidden.vbs
将启动批处理并等待它返回:
'This script is supposed to start hidden!
Set WsShell = CreateObject("W"&"Script.Shell")
WsShell.Run "LongRun.bat", 7, True
'WsShell.Run "REBOOT.EXE ..." 'Must remove comment and complete command line
MsgBox "Rebooting..."
现在LongRun.bat
正在运行,Hidden.vbs
也在运行(但不可见)。
如果某种方式LongRun.bat
被终止,Hidden.vbs
将继续执行并重新启动。
编辑:注意"W"&"Script.Shell"
与"WScript.Shell"
相同,但StackOverflow不允许我编写它!