我仅限于没有VBScript脚本的经验,可以使用一些建议。在启动需要这些驱动器的应用程序之前,我们使用此VBScript脚本映射计算机的网络驱动器。现在我还需要在脚本运行的最后一行之前启动另外两个外部程序。其中一个程序有特殊的启动说明。
[这是第一个以其配置开始的目标] “C:\ Program Files \ Eterlogic Software \ Free Virtual Serial Ports Emulator \ VSPEmulator.exe”-minimize -hide_splash c:/config.vspe
[这是下一步必须开始,但不能开始直到上面的一个] “C:\ Program Files \ SAACUBridge \ SAACUBridge.exe”
这两个必须在下面这个VBScript脚本的LAST行(StartNG.bat)之前运行。
=============================================== ====
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
答案 0 :(得分:1)
我会把你拥有的两个命令:
"C:\Program Files\Eterlogic Software\Free Virtual Serial Ports Emulator\VSPEmulator.exe" -minimize -hide_splash c:/config.vspe
"C:\Program Files\SAACUBridge\SAACUBridge.exe"
在c:\StartNG.bat
的开头,按原样保留VBScript
答案 1 :(得分:0)
这样的事情可以解决问题:
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
' -- keep checking for the process running
Set Service = GetObject("winmgmts:\\.")
for each Process in Service.InstancesOf ("Win32_Process")
While Process.Name <> "PROCESS.exe"
oShell.Run "c:\StartNG.bat", 0, False
'wscript.echo "PROCESS running on " & ComputerName
Wscript.sleep 2000 ' -- Pause for tw seconds, you may want run continually - but test carefully!!
Next
Loop
答案 2 :(得分:0)
您可以从VBScript运行外部命令,而无需先将其写入批处理脚本。替换这个:
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字符串也用双引号分隔,所以内部双引号必须通过加倍来转义,因此表示法:
"""C:\path to\some.exe"" -option"
注意:如果脚本不应该等待前2个程序终止(例如因为它们作为后台进程运行),请从{{1}更改3 rd 参数到True
。如果需要,您还可以在3 False
次来电之间添加一些延迟,方法是在Run
之间添加WScript.Sleep 1000
(根据需要调整数量)。
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
答案 3 :(得分:0)
更改以下部分:
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
致:
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:\Program Files\Eterlogic Software\Free Virtual Serial Ports Emulator\VSPEmulator.exe"" -minimize -hide_splash c:/config.vspe", 1, False
WScript.Sleep 1000 'set sleep time in milliseconds for delay
oShell.Run """C:\Program Files\SAACUBridge\SAACUBridge.exe""", 1, False
WScript.Sleep 1000 'set sleep time in milliseconds for delay
oShell.Run "c:\StartNG.bat", 0, False
批处理文件是一种解决方法,可帮助避免Windows Open File Security警告,因为它在映射的网络驱动器上执行程序。