所以,我只是在我的大学课程中开始编程课程,我们必须编写一个脚本来启动多个程序。任何人都可以帮忙吗? 这就是我到目前为止所做的:
Set objShell = CreateObject("WdScript.Shell")
objShell.Run """C:\Program Files (x86)\Skype\Phone\Skype.exe"""
objShell.Run """C:\Program Files (x86)\Steam\Steam.exe""
Set objShell = Nothing
X=MsgBox("Running Skype and Steam!",0+64,"Succeeded")
答案 0 :(得分:1)
Set objShell = CreateObject("WScript.Shell")
答案 1 :(得分:0)
对这段代码大喊:
Option Explicit
If AppPrevInstance() Then
MsgBox "Instance already running",VbExclamation,"Instance already running"
WScript.Quit
Else
Call Main(Array("c:\toto1.bat",_
"c:\toto2.bat",_
"c:\toto3.bat",_
"%ProgramFiles%\Internet Explorer\iexplore.exe",_
"Skype.exe",_
"Steam.exe"))
End If
'**************************************************************************
Sub Main(colProcessPaths)
Dim ProcessPath
For Each ProcessPath In colProcessPaths
RunProcess(ProcessPath)
Next
End Sub
'**************************************************************************
Sub RunProcess(ProcessPath)
Dim ProcessName : ProcessName = StripProcPath(ProcessPath)
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE Commandline LIKE " & CommandLineLike(ProcessName))
If .Count = 0 Then
With CreateObject("WScript.Shell")
.Run DblQuote(ProcessPath)
End With
Else
Exit Sub
End if
End With
End With
End Sub
'**************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'**************************************************************************
Function StripProcPath(ProcessPath)
Dim arrStr : arrStr = Split(ProcessPath, "\")
StripProcPath = arrStr(UBound(arrStr))
End Function
'**************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'**************************************************************************
'Fonction pour ajouter les doubles quotes dans une variable
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**************************************************************************