VBScript如何启动一个进程?

6
我有一个VB脚本,它可以启动一个exe文件(或者一个没有图形用户界面的进程):
strCom = "Start calc"  
WSHShell.Run(strCom)  

当我打开任务管理器时,它不会启动程序并且我看不到它。
但是当我直接在命令行中输入"Start calc"命令时,它可以打开程序。

我该如何使用脚本来实现这个功能?

4个回答

11

start是内置于cmd.exe中的,它不是一个实际的程序。

WSHShell.Run接受物理文件,而不是cmd内置命令。

因此,您可以编写WSHShell.Run("calc.exe")


很好的答案,但我想指出 WSHShell 需要先初始化。这里是一个使用 Internet Explorer 的示例: CreateObject("WScript.Shell").Run("iexplore") - Dog Lover

4
  1. Starting a system process like calc.exe or cmd.exe

    code

        Dim shl  
        Set shl = CreateObject("Wscript.Shell")  
        Call shl.Run("""calc.exe""")  
        Set shl = Nothing  
        WScript.Quit 
    
  2. Starting a normal process

    code

       Dim shl  
       Set shl = CreateObject("Wscript.Shell")  
       Call shl.Run("""D:\testvbs\someServices.exe""")  
       Set shl = Nothing    
       WScript.Quit
    
  3. You can launch any batch file too using VBscript. just provide the path of batch file in shl.run() while calling it.


使用过 Windows 11。很酷 :) - Naveen Kumar V

2

或者/此外 - 如果使用 start 很重要:

CreateObject("WScript.Shell").Run "%comspec% /c start /wait notepad.exe", 0, True

CreateObject("WScript.Shell").Exec "%comspec% /c start E:\Handapparat\Algorithms\diktaat.pdf"

或其变体。


1
CreateObject("WScript.Shell").Run("**Application**")

我不打算为此脚本制作视频。 尽管我用它制作了一个很酷的错误游戏。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接