在VBScript脚本中插入两个批处理命令 [英] Insert two batch commands inside a VBScript script

查看:103
本文介绍了在VBScript脚本中插入两个批处理命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 VBScript 脚本没有经验,可以使用一些建议.在启动需要这些驱动器的应用程序之前,我们使用此VBScript脚本映射计算机的网络驱动器.现在,在脚本的最后一行运行之前,我还需要启动其他两个外部程序.这些程序之一具有特殊的启动说明.

I have limited to no experience with VBScript scripts and could use some advice. We use this VBScript script to map network drives for a machine before it starts up an application that needs those drives. Now I also need to start two other external programs BEFORE the very last line of the script runs. One of these programs has special startup instructions.

[这是第一个开始进行配置的目标] "C:\ Program Files \ Eterlogic软件\免费虚拟串行端口模拟器\ VSPEmulator.exe" -minimize -hide_splash c:/config.vspe

[THIS IS THE TARGET FOR THE FIRST TO START ALONG WITH ITS CONFIGURATION] "C:\Program Files\Eterlogic Software\Free Virtual Serial Ports Emulator\VSPEmulator.exe" -minimize -hide_splash c:/config.vspe

[这是必须开始的下一个步骤,但直到上述一个操作完成后,它才能启动] "C:\ Program Files \ SAACUBridge \ SAACUBridge.exe"

[THIS IS THE NEXT THAT MUST START, BUT IT CANNOT START UNTIL THE ONE ABOVE DOES] "C:\Program Files\SAACUBridge\SAACUBridge.exe"

这两个脚本必须在下面的此VBScript脚本的LAST行(StartNG.bat)之前向右运行.

Those two must run RIGHT before the LAST line (StartNG.bat) of this VBScript script below.

================================================ ====

===================================================

option explicit
on error resume next
dim oShell, oNetwork

Set oShell=WScript.CreateObject ("WScript.Shell")

WScript.Sleep 15000 'Allow network services to start
set oNetwork=wscript.createobject ("wscript.network")
oNetwork.RemoveNetworkDrive "n:"
oNetwork.RemoveNetworkDrive "r:"
oNetwork.RemoveNetworkDrive "g:"
oNetwork.RemoveNetworkDrive "v:"
WScript.Sleep 10000
oNetwork.MapNetworkDrive "r:", "\\10.81.47.246\audio", false, "NexGen", "7roppu$"
oNetwork.MapNetworkDrive "n:", "\\10.81.47.246\SPOTS1", false, "NexGen", "7roppu$"
oNetwork.MapNetworkDrive "g:", "\\10.81.47.246\SONGS1", false, "NexGen", "7roppu$"
oNetwork.MapNetworkDrive "v:", "\\10.81.47.246\UPDATE", false, "NexGen", "7roppu$"

WScript.Sleep 5000
Dim oFS, fileBat
Set oFS = CreateObject("Scripting.FileSystemObject")
Set fileBat = Nothing
Set fileBat = oFS.CreateTextFile("c:\StartNG.bat", False)
if not fileBat is Nothing Then
   fileBat.WriteLine("v:\hlc\update.exe")
   fileBat.close
end if
oShell.Run "c:\StartNG.bat", 0, False

推荐答案

您可以从VBScript运行外部命令,而无需先将其写入批处理脚本.替换为:

You can run external commands from VBScript without writing them to a batch script first. Replace this:

Dim oFS, fileBat
Set oFS = CreateObject("Scripting.FileSystemObject")
Set fileBat = Nothing
Set fileBat = oFS.CreateTextFile("c:\StartNG.bat", False)
if not fileBat is Nothing Then
   fileBat.WriteLine("v:\hlc\update.exe")
   fileBat.close
end if
oShell.Run "c:\StartNG.bat", 0, False

与此:

oShell.Run """C:\Program Files\Eterlogic Software\Free Virtual Serial Ports Emulator\VSPEmulator.exe"" -minimize -hide_splash c:/config.vspe", 0, True
oShell.Run """C:\Program Files\SAACUBridge\SAACUBridge.exe""", 0, True
oShell.Run "v:\hlc\update.exe", 0, False

由于前两个命令的路径包含空格,因此必须将其放在双引号之间.因为VBScript字符串也用双引号定界,所以内部双引号必须通过将它们加倍来进行转义,因此表示法是:

Since the paths of the first 2 commands contain spaces they must be put between double quotes. Because VBScript strings are delimited with double quotes as well, the inner double quotes must be escaped by doubling them, hence the notation:

"""C:\path to\some.exe"" -option"

注意:如果脚本不应该等待前两个程序终止(例如,因为它们作为后台进程运行),请从True更改3 rd 参数到False.如果需要,您还可以在3个Run调用之间添加一些延迟,方法是在它们之间放置WScript.Sleep 1000(根据需要调整数字).

Note: If the script should not wait for the first 2 programs to terminate (e.g. because they run as background processes) change the 3rd parameter from True to False. If needed you could also add some delay between the 3 Run calls by putting WScript.Sleep 1000 between them (adjust the number as you see fit).

oShell.Run """C:\Program Files\Eterlogic Software\Free Virtual Serial Ports Emulator\VSPEmulator.exe"" -minimize -hide_splash c:/config.vspe", 0, False
WScript.Sleep 1000
oShell.Run """C:\Program Files\SAACUBridge\SAACUBridge.exe""", 0, False
WScript.Sleep 1000
oShell.Run "v:\hlc\update.exe", 0, False

这篇关于在VBScript脚本中插入两个批处理命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆