bat脚本实现后台运行cmd命令

近期工作需要后台运行node.js以及exe程序。默认是会有cmd窗口信息打印的,现在需要隐藏进程(即只能在任务管理器中看到进程,任务栏无法看见)。初始时调用winexec()可以实现exe的后台运行,但是nodejs程序不好使(winexec()只能调用exe程序)。网上查询后通过bat脚本实现。

系统环境:win10_x64

具体如下:

1.新建start.txt文件,输入如下命令:

@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit
:begin

cd "C:UserskaiDesktop"

123.exe

其中,123.exe为需要后台运行的程序(123.exe直接运行是一个窗口程序),C:UserskaiDesktop为123.exe所在路径

注意:不要添加多余的指令运行123.exe,例如start cmd.exe /k "123.exe",进入对应的路径后直接运行程序即可。

2.修改start.txt为start.bat即可。

原文地址:https://www.cnblogs.com/lidabo/p/14781681.html