简体   繁体   English

我想从.bat文件运行第3方.exe文件而没有可见的命令提示符

[英]I want to run a 3rd party .exe file from a .bat file without a visible command prompt

Firstly I have created VBScript to run a batch file without a visible command prompt. 首先,我创建了VBScript以运行没有可见命令提示符的批处理文件。

Following is the code: 以下是代码:

Set WshShell = CreateObject("WScript.Shell" ) 
WshShell.Run Chr(34) & ("D:\Intouch_Printer_SW\spool12\spltotext.bat") & Chr(34), 0 
Set WshShell = Nothing 

Following is my batch file code to run a third party .exe file. 以下是我运行第三方.exe文件的批处理文件代码。

for %%f in (C:\WINDOWS\system32\spool\PRINTERS\*.SPL) do (
    echo %%~nf
    start "" D:\Intouch_Printer_SW\spool12\spool.exe "C:\WINDOWS\system32\spool\PRINTERS\%%~nf.SPL" "Intouch Printer"
)

Whenever I run my .vbs code a console window pops up, I want to do all of it without a visible command prompt. 每当我运行.vbs代码时,都会弹出一个控制台窗口,我想在没有可见命令提示符的情况下执行所有操作。

I think I am getting a black window due to this snippet: 由于以下代码片段,我认为我得到了一个黑色的窗口:

start "" D:\Intouch_Printer_SW\spool12\spool.exe "C:\WINDOWS\system32\spool\PRINTERS\%%~nf.SPL" "Intouch Printer"

start opens the command in a new window. start在新窗口中打开命令。 It isn't required for running console applications, so you can simply remove it: 运行控制台应用程序不是必需的,因此您可以将其删除:

for %%f in (C:\WINDOWS\system32\spool\PRINTERS\*.SPL) do (
    echo %%~nf
    D:\Intouch_Printer_SW\spool12\spool.exe "C:\WINDOWS\system32\spool\PRINTERS\%%~nf.SPL" "Intouch Printer"
)

In addition I would recommend running the batch script synchronously from the VBScript (3rd argument to the Run method set to True ), to avoid undesired side effects should anyone ever modify the VBScript. 另外,我建议从VBScript(将Run方法的第3个参数设置为True )同步运行批处理脚本,以避免任何人修改VBScript产生的不良影响。

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """D:\Intouch_Printer_SW\spool12\spltotext.bat""", 0, True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM