如何停止在批处理程序中启动的VBScript?

时间:2017-03-07 02:03:01

标签: batch-file vbscript wsh

所以我在批量编程中制作游戏,我决定在标题菜单屏幕上添加一些主题音乐。我添加音乐的方式是使用WScript和VBScript来播放mp3文件。

唯一的问题是,一旦启动它就会在后台播放,而不是通过批处理文件播放,因此,一旦你开始游戏,主题音乐就会继续播放。我已经将这个脚本用于简单的小声音,这些声音很快就会结束,所以它以前从来都不是问题。

所以我的问题是,是否可以从批处理文件中停止脚本,而不必执行旧的 Ctrl + Alt + Del < / kbd>方法?

这是我的文本脚本:

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

2 个答案:

答案 0 :(得分:1)

使用命令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*"

答案 1 :(得分:0)

我总是用这个。

configurations.all {
    resolutionStrategy {
        force "com.android.support:exifinterface:$rootProject.supportLibVersion"
    }
}

dependencies {
    ...
    implementation "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
    implementation "com.android.support:recyclerview-v7:$rootProject.supportLibVersion"
    implementation "com.android.support:cardview-v7:$rootProject.supportLibVersion"
    ...
}