Closing a pdf file via a batch script (.bat) - windows

I use a windows batch file .bat for running latex command to create a pdf. To open the final pdf file, I wrote
pdflatex %2
START "" %2.pdf
Where %2 is the filename I passed it as argument. Problem is, whenever, I run the script, I have to manually close the pdf file and run the script. I want to add a command to first close the opened pdf and then run latex command and then open it
<CLOSE THE PDF FILE>
pdflatex %2
START "" %2.pdf
I didn't find a CLOSE command in the list of available commands, Information on batch files

I highly recommend SS64 for a list of batch commands. The command you're looking for is taskkill. I don't know pdflatex appears in the task manager, but the code is going to be something along the lines of
taskkill /IM acrord32.exe
Replace acrord32.exe with whatever it appears as in the task manager. You may also need to add the /F flag before the /IM to force close the program.

Related

How to close cmd window openned bat file with another bat file or program

I created a node.js program, and I run it using the following .bat file:
cd C:\Users\user\Documents\programmingStuff\jsProgramsFolder
node .
#pause
I now want to close the cmd window created by this specific bat file with another bat file or program.
Searching for the answer only provided results for how to close the window in the same bat file.
Is this possible? If so, how can it be done?
taskkill lets you filter by window title, and title lets you set the window title.
In the script that you have posted, add the line title NodeLauncher (you can call it something else as long as it's unique to this particular window.)
In another batch file, run taskkill /IM cmd.exe /FI "WINDOWTITLE eq NodeLauncher"

Keep cmd.exe console window with specific title open?

in Windows 7 x64 SP1 I need to create a batch file (.bat) which keeps the cmd.exe console window open and has a specific title:
#ECHO OFF
title notepadtest
#ECHO ON
start "" /WAIT notepad
But this batch file keeps opening an infinite number of cmd.exe console windows in an unstoppable loop!
How can I create a batch file (.bat) which creates only ONE cmd.exe console window and keeps it open and has a specific title?
Please ensure that your batchfile is not named notepad.cmd or notepad.bat or anything like any system or external command. Name it something like mynotepad.cmd instead., then try this one please:
#echo off
title notepadtest
start "" /w notepad.exe
cmdline and batch files typically works like this. When a command is issued, it first checks the local path, where the script was launched from for the command, if not found, it will check your environment and system environment. So if you name a batchfile notepad.bat your batch is actually starting itself over and over, instead of finding notepad.exe in the environment variables.
Always name batch files something unique and not system/external command related.
Always use full executable name in a batch, like start "" /w notepad.exe and not start "" /w notepad

Stop CMD opening when bat file launched

I have this code
start /b error.vbs
When I run it, a CMD opens for half a second, then it runs. How would I remove or hide the CMD?
You don't need a batch file to launch a VBScript script. Just run the .vbs file directly with with wscript.exe (if you don't want the console). For example:
wscript error.vbs

How to end a batch file with an open command window at a certain folder location

This seems like it should be ridiculously simple but I cannot find the answer online or in these forums.
I want to run a command from a batch file, leave the command window open and end at a particular file location.
I can't seem to get both to happen in the same window. This is for a script to run an automated task everytime and leave the window open to run a 2nd task that has a variable input.
start cmd /k c:\users\test\desktop\dmiwtool1.1\win64\dmiwtoolx64.exe & cd c:\users\test\desktop\dmiwtool1.1\win64\
If I run either by itself, they work (runs the exe, ends at /desktop prompt), but in this sequence only the first runs.
this works here:
#ECHO OFF
START /b "" "path\program.exe" "parameter"
CD %UserProfile%\Desktop
Do not use setlocal in your Batch or put endlocal in the line before the CD command.
This should work:
start cmd /k "c:\users\test\desktop\dmiwtool1.1\win64\dmiwtoolx64.exe & cd c:\users\test\desktop\dmiwtool1.1\win64\"
If you leave out the quote marks, the start command and the cd command are run separately.

Running vbscript from batch file

I just need to write a simple batch file just to run a vbscript. Both the vbscript and the batch file are in the same folder and is in the SysWOW64 directory as the vbscript can only be execute in that directory. Currently my batch file is as follows:
#echo off
%WINDIR%\SysWOW64\cmd.exe
cscript necdaily.vbs
But the vbscript wasn't executed and just the command prompt is open. Can anyone tell me how can i execute the vbscript when i run this batch file?
You can use %~dp0 to get the path of the currently running batch file.
Edited to change directory to the VBS location before running
If you want the VBS to synchronously run in the same window, then
#echo off
pushd %~dp0
cscript necdaily.vbs
If you want the VBS to synchronously run in a new window, then
#echo off
pushd %~dp0
start /wait "" cmd /c cscript necdaily.vbs
If you want the VBS to asynchronously run in the same window, then
#echo off
pushd %~dp0
start /b "" cscript necdaily.vbs
If you want the VBS to asynchronously run in a new window, then
#echo off
pushd %~dp0
start "" cmd /c cscript necdaily.vbs
This is the command for the batch file and it can run the vbscript.
C:\Windows\SysWOW64\cmd.exe /c cscript C:\Windows\SysWOW64\...\necdaily.vbs
Just try this code:
start "" "C:\Users\DiPesh\Desktop\vbscript\welcome.vbs"
and save as .bat, it works for me
Batch files are processed row by row and terminate whenever you call an executable directly.
- To make the batch file wait for the process to terminate and continue, put call in front of it.
- To make the batch file continue without waiting, put start "" in front of it.
I recommend using this single line script to accomplish your goal:
#call cscript "%~dp0necdaily.vbs"
(because this is a single line, you can use # instead of #echo off)
If you believe your script can only be called from the SysWOW64 versions of cmd.exe, you might try:
#%WINDIR%\SysWOW64\cmd.exe /c call cscript "%~dp0necdaily.vbs"
If you need the window to remain, you can replace /c with /k
Well i am trying to open a .vbs within a batch file without having to click open but the answer to this question is ...
SET APPDATA=%CD%
start (your file here without the brackets with a .vbs if it is a vbd file)
You should put your .bat file in the same folder as your .vbs file and call the following code inside the .bat file.
start cscript C:\filePath\File.vbs

Resources