如何停止在批处理程序中启动的 VBScript?
How to stop a VBScript that was started in a batch program?
所以我正在批量编程制作游戏,我决定在标题菜单屏幕中添加一些主题音乐。我添加音乐的方法是使用 WScript
和 VBScript 来播放 mp3 文件。
唯一的问题是,一旦启动它就会在后台播放,而不是通过批处理文件播放,因此,一旦您启动游戏,主题音乐就会继续播放。我已经将此脚本用于简单的小声音,这些声音很快就会结束,所以以前从来都不是问题。
所以我的问题是,是否可以从批处理文件中停止脚本,而不必执行旧的 Ctrl+Alt+删除方法?
这是我的文本脚本:
set music=ThemeMusic.mp3
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%music%"
echo Sound.Controls.play
echo Do While Sound.currentmedia.duration = 0
echo WScript.Sleep 100
echo Loop
echo WScript.Sleep (Int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /max sound.vbs
这里是通过批处理文件打开的单独 VBScript 的代码:
Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = "ThemeMusic.mp3"
Sound.Controls.play
Do While Sound.currentmedia.duration = 0
WScript.Sleep 100
Loop
WScript.Sleep (Int(Sound.currentmedia.duration)+1)*1000
使用命令TASKKILL /IM wscript.exe
。但是,请记住,这将结束所有 VBScript 进程。
以后,在控制台中使用 TASKKILL /?
进行各种其他方法。它将显示以下内容:
TASKKILL [/S system [/U username [/P [password]]]]
{ [/FI filter] [/PID processid | /IM imagename] } [/T] [/F]
Description:
This tool is used to terminate tasks by process id (PID) or image name.
Parameter List:
/S system Specifies the remote system to connect to.
/U [domain\]user Specifies the user context under which the
command should execute.
/P [password] Specifies the password for the given user
context. Prompts for input if omitted.
/FI filter Applies a filter to select a set of tasks.
Allows "*" to be used. ex. imagename eq acme*
/PID processid Specifies the PID of the process to be terminated.
Use TaskList to get the PID.
/IM imagename Specifies the image name of the process
to be terminated. Wildcard '*' can be used
to specify all tasks or image names.
/T Terminates the specified process and any
child processes which were started by it.
/F Specifies to forcefully terminate the process(es).
/? Displays this help message.
Filters:
Filter Name Valid Operators Valid Value(s)
----------- --------------- -------------------------
STATUS eq, ne RUNNING |
NOT RESPONDING | UNKNOWN
IMAGENAME eq, ne Image name
PID eq, ne, gt, lt, ge, le PID value
SESSION eq, ne, gt, lt, ge, le Session number.
CPUTIME eq, ne, gt, lt, ge, le CPU time in the format
of hh:mm:ss.
hh - hours,
mm - minutes, ss - seconds
MEMUSAGE eq, ne, gt, lt, ge, le Memory usage in KB
USERNAME eq, ne User name in [domain\]user
format
MODULES eq, ne DLL name
SERVICES eq, ne Service name
WINDOWTITLE eq, ne Window title
NOTE
----
1) Wildcard '*' for /IM switch is accepted only when a filter is applied.
2) Termination of remote processes will always be done forcefully (/F).
3) "WINDOWTITLE" and "STATUS" filters are not considered when a remote
machine is specified.
Examples:
TASKKILL /IM notepad.exe
TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
TASKKILL /F /IM cmd.exe /T
TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"
我一直用这个。
taskkill /F /IM wscript.exe /T
所以我正在批量编程制作游戏,我决定在标题菜单屏幕中添加一些主题音乐。我添加音乐的方法是使用 WScript
和 VBScript 来播放 mp3 文件。
唯一的问题是,一旦启动它就会在后台播放,而不是通过批处理文件播放,因此,一旦您启动游戏,主题音乐就会继续播放。我已经将此脚本用于简单的小声音,这些声音很快就会结束,所以以前从来都不是问题。
所以我的问题是,是否可以从批处理文件中停止脚本,而不必执行旧的 Ctrl+Alt+删除方法?
这是我的文本脚本:
set music=ThemeMusic.mp3
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%music%"
echo Sound.Controls.play
echo Do While Sound.currentmedia.duration = 0
echo WScript.Sleep 100
echo Loop
echo WScript.Sleep (Int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /max sound.vbs
这里是通过批处理文件打开的单独 VBScript 的代码:
Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = "ThemeMusic.mp3"
Sound.Controls.play
Do While Sound.currentmedia.duration = 0
WScript.Sleep 100
Loop
WScript.Sleep (Int(Sound.currentmedia.duration)+1)*1000
使用命令TASKKILL /IM wscript.exe
。但是,请记住,这将结束所有 VBScript 进程。
以后,在控制台中使用 TASKKILL /?
进行各种其他方法。它将显示以下内容:
TASKKILL [/S system [/U username [/P [password]]]]
{ [/FI filter] [/PID processid | /IM imagename] } [/T] [/F]
Description:
This tool is used to terminate tasks by process id (PID) or image name.
Parameter List:
/S system Specifies the remote system to connect to.
/U [domain\]user Specifies the user context under which the
command should execute.
/P [password] Specifies the password for the given user
context. Prompts for input if omitted.
/FI filter Applies a filter to select a set of tasks.
Allows "*" to be used. ex. imagename eq acme*
/PID processid Specifies the PID of the process to be terminated.
Use TaskList to get the PID.
/IM imagename Specifies the image name of the process
to be terminated. Wildcard '*' can be used
to specify all tasks or image names.
/T Terminates the specified process and any
child processes which were started by it.
/F Specifies to forcefully terminate the process(es).
/? Displays this help message.
Filters:
Filter Name Valid Operators Valid Value(s)
----------- --------------- -------------------------
STATUS eq, ne RUNNING |
NOT RESPONDING | UNKNOWN
IMAGENAME eq, ne Image name
PID eq, ne, gt, lt, ge, le PID value
SESSION eq, ne, gt, lt, ge, le Session number.
CPUTIME eq, ne, gt, lt, ge, le CPU time in the format
of hh:mm:ss.
hh - hours,
mm - minutes, ss - seconds
MEMUSAGE eq, ne, gt, lt, ge, le Memory usage in KB
USERNAME eq, ne User name in [domain\]user
format
MODULES eq, ne DLL name
SERVICES eq, ne Service name
WINDOWTITLE eq, ne Window title
NOTE
----
1) Wildcard '*' for /IM switch is accepted only when a filter is applied.
2) Termination of remote processes will always be done forcefully (/F).
3) "WINDOWTITLE" and "STATUS" filters are not considered when a remote
machine is specified.
Examples:
TASKKILL /IM notepad.exe
TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
TASKKILL /F /IM cmd.exe /T
TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"
我一直用这个。
taskkill /F /IM wscript.exe /T