Errorlevel in a For loop (Windows batch)

Add setlocal EnableDelayedExpansion to the start of your script, then use !errorlevel! instead of %errorlevel% Delayed Expansion will cause variables to be expanded at execution time rather than at parse time ~ http://ss64.com/nt/delayedexpansion.html The answer to another question that pointed me in the right direction: Errorlevel of command executed by batch for loop

windows batch file rename

Use REN Command Ren is for rename ren ( where the file is located ) ( the new name ) example ren C:\Users\&username%\Desktop\aaa.txt bbb.txt it will change aaa.txt to bbb.txt Your code will be : ren (file located)AAA_a001.jpg a001.AAA.jpg ren (file located)BBB_a002.jpg a002.BBB.jpg ren (file located)CCC_a003.jpg a003.CCC.jpg and so on IT WILL NOT WORK IF … Read more

Passing around multi-line strings

You can create directly multiline strings with the caret (one empty line is required). setlocal EnableDelayedExpansion set multiLine=This is a ^ multiline text^ line3 echo !multiLine! Or you can create first a newline character. setlocal EnableDelayedExpansion set LF=^ rem Two empty lines are required set multiLine=This is a!LF!multiline text!LF!line3 echo !multiLine! An explanation how this … Read more

Task scheduler cannot open batch file when set to run whether user is logged on or not

I have resolved this problem with help from a contractor who was doing some other work for my institution. In the properties window for the task, on the Action tab, when creating or editing the action that opens the batch file (in my case test.bat), there is the “Program/script:” field and there is also a … Read more

How to split double quoted line into multiple lines in Windows batch file?

I see three possible workarounds. 1) Building the line combining multiple for-parameters. @echo off SETLOCAL EnableDelayedExpansion set “line=” for %%a in (“line1” “line2” “line3” “line4″ ) do set line=!line!%%~a echo !line! Drawback: It drops lines, when there is a ? or * in the text. 2) Leaving the “quote” at the end of each line … Read more

Run a shortcut with a batch file

The help for start contains this tidbit: START [“title”] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL] [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B] [command/program] [parameters] “title” Title to display in window title bar. In other words the first quoted string will … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)