Unable to invoke multiple batch files - batch-file

I have VBScript file as follows which launches multiple batch files.
Invoke.vbs
const RunbatchtLocation = "C:\Temp"
Set shell = WScript.CreateObject("WScript.Shell")
shell.run RunbatchtLocation & "\Launch.bat",1,True
Launch.bat
start cmd /k "C:\Temp\All10.bat"
start cmd /k "C:\Temp\30.bat"
C:\Temp\50.bat
The above file able will executed All10.bat , 30.bat and 50.bat which is work fine.
My problem is here in All10.bat which is as follows:
CALL "c:\temp\10-1.bat"
CALL "c:\temp\10-2.bat"
CALL "c:\temp\10-3.bat"
It starts with 10-1.bat and is able to execute all the specified files, but after it completes it stops and never executes 10-2.bat or 10-3.bat.
Will someone tell me where I am going wrong?

Related

move command fails from batch file. But runs successfully when executed from command prompt

I have a simple move command as:
move tfa.war ..\..\..\tomcat\webapps
When i run this command in command prompt it works fine. But when i put this command in a batch file with variables like so, and execute the batch file in command prompt it fails with the message "The system cannot find the file specified".
cmd.exe /C webapp_deploy.bat tfa
And the contents of webapp_deploy.bat:
#ECHO OFF
set app_name=%~1
set webapps_directory=..\..\..\tomcat\webapps
move %app_name%.war %webapps_directory%
Any help would be much appreciated!

How to make .bat do not call cmd

Soo
#echo off Turn off command echoing and don't echo the command turning it off. But how to make bat file do not call CMD at all ?
This makes so little sense. If you're asking how to stop a batch file from showing the command prompt window, you cannot.
You can however use a VBScript file to launch the batch file silently. The script would look something like:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\path-to-batch-file\batchfile.bat" & Chr(34), 0
Set WshShell = Nothing
I think what you're trying to do probably isn't a job for a batch file.
A batch file is a script, not a binary executable. A script always needs an interpreter to run. For batch scripts, the interpreter is cmd.exe, so you cannot avoid invoking cmd.exe at all. It makes no sense to run a script without its interpreter. This is true everywhere.
All you can do is hiding the console window that cmd.exe brings up when it's invoked, most easily done with the help of a VBScript:
CreateObject("Wscript.Shell").Run "C:\path\to\your.bat", 0, False

Running a batch (.bat) file from a VB macro (.vbs)

I am having issues getting a simple batch file (opening command prompt) to run from a vbs macro, I know this question gets asked a lot and I have tried many different suggested solutions for this without success. I am using notepad ++ to run the scripts/VB code for testing.
I have verified that the .bat file will execute correctly by itself, any suggestion on how to get this to work correctly would be greatly appreciated.
Here is my code for each instance.
VB CODE:
Sub CallBATCH()
Dim argh As Double
argh = Shell.Run "C:\Temp\cmdPrompt.bat"
End Sub
BATCH FILE:
start cmd.exe /k
EDIT: The following is the .bat file that I actually intend on calling up:
#echo OFF
title AutoCAD DWG Duplicator
color 0a
:start
set /P TemplateName=Please enter the template name you wish to copy:
set /P NumberOfCopies=Please enter how many copies you wish to make:
set Pathname="<filepath>"
cd /d %Pathname%
:init
for /L %%f in (1,1,%NumberOfCopies%) do copy %TemplateName%.dwg C:\Temp\%%f%TemplateName%.dwg
You seem to be calling a .BAT file that in turn opens a command prompt with START. I'm unclear on why you need the .BAT at all.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /K"
Set oShell = Nothing
The /K parameter will open the command prompt window and keep it open. You've supplied no parameters for START and no commands to execute when the command prompt opens so this should do what you are looking for. More at: Run Method (Windows Script Host)

Running master bat file in invisible mode

I have a master.bat file which has...
call file1.bat
call file2.bat
call file3.bat
call file4.bat
I want to schedule it on my Windows server 2008 to run in silent/invisible mode.I'm looking for some way to run this master.bat without anything visible to the user (no window, CMD interface ,no taskbar name etc..)
I don't want to install any batch to exe software.
I tried by changing the User running the task to "SYSTEM" and it has the work done but I can't do this in actual.
I have found that Windows Script Host’s Run Method allows you to run a script in invisible mode as.....
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Batch Files\master.bat" & Chr(34), 0
Set WshShell = Nothing
but no more file please :) any other suggestion for this.
EDIT1
Considering the limited options available..it would be OK to use Windows Script Host’s Run Method,but how i can schedule master.vbs in task scheduler.. ?
For an extended view of it, check for hybrid batch / vbscript / javascript files here in stackoverflow.
Save this as master.cmd and adapt as needed.
#if (#This==#IsBatch) #then
#echo off
rem **** batch zone *********************************************************
rem Check if started from javascript part of script.
rem We are checking an environment variable set from javascript part.
if "%_run_hidden_%"=="true" (
goto startBatchWork
)
rem if not started from javascript, call javascript part to restart batch.
wscript //E:JScript "%~dpnx0"
exit /b
:startBatchWork
rem Here starts the real work of the batch file
msg %username% "Batch file running hidden"
rem End of batch area. Ensure batch ends execution before reaching
rem javascript zone
exit /b
#end
// **** Javascript zone *****************************************************
// Instantiate the needed component to interact with Shell
var shell = WScript.CreateObject('WScript.Shell');
// Set the environment variable that the batch part will check to know
// it's running hidden
shell.Environment('Process').Item('_run_hidden_')='true';
// start the batch part of the script calling %comspec% with the current
// script as parameter, hidden (0) and not waiting for it to end (false)
shell.Run('"' + shell.ExpandEnvironmentStrings('%comspec%') + '" /c "' + WScript.ScriptFullName + '"', 0, false );
// All done. Exit
WScript.Quit(0);
CMDOW is a tool that will allow the batch to run hidden.
It is flagged as a hack tool by various AV programs.

How to close cmd window when using a batch file?

New to batch files, first try actually. Trying to make a simple batch file that will open a new instance of notpad++. The batch file works and a new notpad++ window is opened, but the cmd window also stays open as well. How do I close the cmd window within the batch file after the new instance of notepad has been lauched?
#ECHO OFF
CALL cd C:\Program Files (x86)\Notepad++\
CALL notepad++.exe -multiInst
You can use start:
start notepad++
And there should be no need to use an explicit exit from the batch (which is done either via goto :eof or exit /b) as the start call returns immediately.
You can exit from command line only after quiting from notepad++.
1. If you wanna exit from cmd after quiting from notepad++, add EXIT to the end of your batch file.
2. Why don't you use shortcut instead of batch file to start notepad++?

Resources