-2

I want to run a .bat file that runs another .bat file in a new cmd, but I want to hide the newly opened cmd or run it in background. I don't want to use .vbs method. Is there another way possible?

R.Rikshit
  • 1
  • 2
  • Please use the search function before posting questions that have more than likely been asked before: https://stackoverflow.com/questions/1449188/running-windows-batch-file-commands-asynchronously – Dan Hogan Jan 18 '19 at 19:46

1 Answers1

0

There are only really two methods, to sort of simulate it, basically you launch the file without creating a new shell, however, hiding all the commands would make sure it does not show any, also use cls as it will ensure that it does not show you what it launches, but it is not fool proof:

batch1.cmd

start "" /b batch2.cmd
cls

batch2.cmd

@echo off
echo Hello World>nul
ping localhost>nul
(echo hello world>Mytest.txt)>nul

The line (echo hello world>Mytest.txt)>nul is to simulate how you can pipe infomation to a file, but still pipe the screen output to nul so it does not display on screen.

Or you can run the second batch in minimized mode, but that can be maximized or restored by a user:

batch1.cmd

start "" /min batch2.cmd

batch2.cmd

@echo off
echo Hello World>nul
ping localhost>nul
(echo hello world>Mytest.txt)>nul

but, not sure why you do not want to do the vbs method as it is surely the best and easiest method.

Set MyScript    = CreateObject("WScript.Shell")
MyScript.Run "f:\login.bat", 0, False
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • if we use vbs method then how to run vbs file. Because on double clicking it opens in notepad – R.Rikshit Jan 17 '19 at 13:51
  • You can simply associate the file type to open with cscript. Right click any .vbs file, select open with, select always use this program to open the file, select the option to browse file, then browse to `C:\Windows\System32\cscript.exe` and select open. – Gerhard Jan 17 '19 at 14:05