Starting one file after another in batch - batch-file

I'm quite new to batch and I'm currently trying to run some Powerpoint presentations one after another. The thing is that I want it to look for all presentations that exists in my folder and then start one presentation after another.
I did this with this line
for %%f in (/f E:\PP\*.pptx) do start "" "C:\Program Files (x86)\Microsoft Office\Office14\PPTVIEW.exe" /F "%%f"
The problem now is that it runs every presentation at the same time. I kind of expected this already but I don't know how to manage that it does what I want to do.
Maybe you can help me. Thanks a lot.

This will give you one file, give a timeout of 5 seconds, open the next.
#echo off
for %%f in (E:\PP\*.pptx) do (
start "" "C:\Program Files (x86)\Microsoft Office\Office14\PPTVIEW.exe" /F "%%f"
timeout /t 5 >nul
taskkill /IM "PPTVIEW.exe"
)
keep in mind, this will open each 5 seconds after each other, but will not close the previous one, for that you need to run taskkill on the previous, before opening the new one.
For autoexit on a presentation (using powerpoint):
goto Options > advanced > untick the "end with blackslide" tickbox then simply run this code:
for %%f in (E:\PP\*.pptx) do start /w "" "C:\Program Files (x86)\Microsoft Office\Office14\PPTVIEW.exe" /F "%%f"

Related

I'm trying to make a batch file that simply opens and saves an xml file

I need to open an XML file save it without modifying it and then restart a program, right now I have two batch files to do it.
notepad.exe "C:\Users\Max Singh\AppData\Local\Microsoft\Windows Live\Services\Cache\config.xml"
Then I manually save in notepad then run the second file,
TASKKILL /F /IM sidebar.exe
START sidebar.exe
I want to be able to do this in one file without me needing to manually save but I don't know how in a batch file.
Assuming that the only reason to open and save the file is to change its modified time, you could try:
COPY /y config.xml config.xml.new
RENAME config.xml.new config.xml
TASKKILL /F /IM sidebar.exe
START sidebar.exe
I presume this is the commonly touted FIX
For a Windows 7 Sidebar is "Hung (non updating)"
Thus needs to be killed and restarted !
I am not certain if this is the best method, however you are the client.
but do read the notes in the comments from others, with more experience.
pushd "C:\Users\Max Singh\AppData\Local\Microsoft\Windows Live\Services\Cache"
type config.xml > config.tmp
copy /y config.tmp config.xml
del config.tmp
popd
Rem Try the following line either without the /F or change it to /T
Taskkill /F /IM sidebar.exe
Rem The suggested method is to wait a few seconds so have added 5 seconds
Timeout 5
start sidebar.exe
Note the above is the minimal file for testing and once happy you can add
#echo off as your first line
You should add the full paths as per comments to guard against loose cannons that may have a similar name. So the second half should be.
%SystemRoot%\System32\taskkill.exe /IM sidebar.exe
%SystemRoot%\System32\timeout.exe 5
Start "" "%ProgramFiles%\Windows Sidebar\sidebar.exe"

Batch File to Open Multiple PDFs | Only Opening 1 at a Time

I recently "discovered" batch files - and have made a few successful ones to help open tedious amounts of files. However, this morning when trying to make on to open 45 pdfs at the same time it wouldn't work.
I used the instructions from here (under Kenp94's answer, and picture below). However, it just opens one at a time and waits until I close the opened pdf before opening the next. I would like to open them all at the same time.
My file looks like this: and is saved in .bat format.
How do I go about getting my files to open all at the same time.
That said, I have checked Opening multiple PDF documents using batch file and Creating a PDF file tracker as Batch file and I feel my approach is different enough that is warrants a separate question as opposed to gleaning the answer from there - or perhaps I simply don't understand Batch files well enough...
Thanks!
Possible solutions from a batch-file:
#For %%I In (*.pdf)Do #Start "" "%%I"
This however suffers from a potential issue, in that *.pdf matches all extensions which begin with .pdf.
To properly limit it to only .pdf extensions, you could use the internal Dir command together with findstr:
#For /F Delims^=^ EOL^= %%I In ('Dir /B/A-D "*.pdf" 2^>NUL^|FindStr ILE ".pdf"')Do #Start "" "%%I"
Alternatively, you could use Where.exe:
#For /F Delims^=^ EOL^= %%I In ('Where .:*.pdf" 2^>NUL')Do #Start "" "%%I"
Use the /WAIT switch to the start command
for %%v in (*.pdf) do start "" /WAIT "%%v"

Scheduled task and printer

i want to watch a folder on my Win7 64bit Machine for new pdf files - and print them autmatically when there is a pdf file in the folder. After printing, the pdf file should be moved in a subfolder. So, after some google research i did a small batch file.
cd "D:\print"
for %%i in (*.pdf) do (
"C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" /print "%%i"
timeout /T 10 /nobreak
move D:\print\*.pdf D:\print\printed
echo %%i
)
I stored this in folder d:\print as print.cmd . When i start the cmd by doubleclick, my printer starts working and the pdf file moves to the subfolder i defined (D:\print\printed).
To watch the folder, i had the idea to create a sheduled task that repeat this cmd-script all 5 minutes.
BUT:
This dont work, when the script is started via scheduled tasks, the printer is not working - the "movement" of the file instead, is working.
I entered in the scheduled task:
Program: C:\Windows\SysWOW64\cmd.exe
Argument: /c"d:\print\print.cmd"
Any idea, why i cant acces the printer via the scheduled task?
The printer is connected via usb.
Hope i could provide necessary information! Thanks for your answers!
Change this line: move D:\print\*.pdf to move /Y D:\print\%%i
Point the scheduled task to actually start your batch file instead of calling cmd and putting the path to your script in the arguments.
You could also edit the batch file and code it to loop every 5 minutes so you only have to start it once:
PushD %~dp0
:start
for %%i in ("D:\print\*.pdf") do (
"C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" /print "%%i"
move /y "%%i" "D:\print\printed"
echo %%i
)
timeout /T 300 /nobreak
goto start

missing "search" arguments in batch

I have this in my batchfile and that works. My problem is that i use it on diffrent computers and they does not store "symatech" the same way.
#ECHO === Checking for Symantech Products
IF NOT EXIST "C:\Program Files\Symantec" GOTO DoneSymantec
ECHO One moment while we remove Symantec Software...
Call "%~d0\exe\Norton_Removal_Tool.exe"
:DoneSymantec
So my question is, is there a way to have it like this: if not exist *any folder contain norton or symantech in program files goto donesymantech
dir /b /s /ad "c:\program files\symantec will search recursive for a folder "symantec", starting in "c:\program files"
Check %errorlevel%, it will be 0 if found, 1, if not found.
Theoretical you can start in "C:\", but that would take a quite long time to finish.
It is much faster, if you know where to start the search ("c:\program files" in your example)
If needed, start a second search in "C:\Program Files (x86)" instead of only one search over the whole disk.
If you don't want to see the output of dir, just redirect it to nirwana (>nul). This will also quicken the search, because printing to the screen is quite slow.
EDIT: if you should need the path instead of only knowing "if exist":
for /F "delims=" %%j in ('dir /b /s /ad "c:\Program Files\symantec" "c:\Program Files (x86)\symantec"') do #echo %%j
(searches in "Program Files" and "Program Files (x86)"; adapt as needed)

Execute shortcut links from a batch file and don't wait for application to exit

I have several applications that I tend to need open at the same time, and rather than relying solely on the Startup folder to launch them at the same time (and so I can reopen all of them if some were closed at some point throughout the day) I created a folder full of shortcuts in a similar fashion to Linux's runlevel startup links. So in the folder I have shortcut links similar to:
S00 - Outlook.lnk
S01 - Notepad++.lnk
S02 - Chrome.lnk
S03 - Skype.lnk
I created a batch file that will loop through all the links that match the naming format and launch them. The contents of that batch file currently is:
#FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO "%%f"
It will launch most of the links I try just fine, but some will launch and wait for the process to exit, thus preventing further scripts from opening. Is there any way to execute the shortcuts without waiting for processes to exit within the batch file? Or is this a lost cause and I should look for a Powershell solution instead?
Things I've tried so far:
Changing the contents to
#FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO START /B /I "%%f"
It launches the command prompt in a background process, but never actually launches the target of the link.
Changing the contents to
#FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO %comspec% /k "%%f"
It launches the first link, but waits.
Try the first way, but take the /B off of the START command. That way, the process will launch in a new window, so it shouldn't cause it to wait.
With the /B, it's going to launch the process in the same window. So if that process blocks for some reason, then you won't get control back until it finishes. For example, consider the following batch file, foo.bat (you need sleep command for this, I have cygwin so it comes with that):
echo hi
sleep 5
From a command prompt, if you type
START /B foo.bat
you'll notice that control won't come back to the command prompt until the sleep finishes. However, if we do this:
START foo.bat
then control comes back immediately (because foo.bat starts in a new window), which is what you want.
dcp's answer pointed in the right direction by trying it without the /B flag, but it wasn't the solution. Apparently START will take the first quoted string, regardless of the order of parameters passed to it, as the title of the new window rather than assuming it is the executable/command. So when the START processes launched they had the shortcut links as the title of the window, and the starting directory was the working directory of the main batch file. So I updated my file to batch file to the following and it works:
#FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO START /B /I "TITLE" "%%f"

Resources