简体   繁体   中英

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.

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.

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.

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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