Windows batch script to read an .ini file

Here’s a command file (ini.cmd) you can use to extract the relevant values: @setlocal enableextensions enabledelayedexpansion @echo off set file=%~1 set area=[%~2] set key=%~3 set currarea= for /f “usebackq delims=” %%a in (“!file!”) do ( set ln=%%a if “x!ln:~0,1!”==”x[” ( set currarea=!ln! ) else ( for /f “tokens=1,2 delims==” %%b in (“!ln!”) do ( set … Read more

Windows 7 batch files: How to check if parameter has been passed to batch file

if %1.==. dir will break if the parameter includes various symbols like “, <, etc if “%1″==”” will break if the parameter includes a quote (“). Use if “%~1″==”” instead: if “%~1″==”” ( echo No parameters have been provided. ) else ( echo Parameters: %* ) This should work on all versions of Windows and … Read more

Windows Batch: How to add Host-Entries?

I would do it this way, so you won’t end up with duplicate entries if the script is run multiple times. @echo off SET NEWLINE=^& echo. FIND /C /I “ns1.intranet.de” %WINDIR%\system32\drivers\etc\hosts IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^62.116.159.4 ns1.intranet.de>>%WINDIR%\System32\drivers\etc\hosts FIND /C /I “ns2.intranet.de” %WINDIR%\system32\drivers\etc\hosts IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^217.160.113.37 ns2.intranet.de>>%WINDIR%\System32\drivers\etc\hosts FIND /C /I “ns3.intranet.de” %WINDIR%\system32\drivers\etc\hosts … Read more

Schedule a Python script via batch on windows (using Anaconda)

I would be a bit careful in calling python directly through environment as one never knows if the internals for activate function has changed. I’m just using basic bat-script to help me out. SET log_file=%cd%\logfile.txt call C:\Anaconda3\Scripts\activate.bat cd \script_directory python script.py arg1 arg2 > %log_file% This script saves the log-file wherever the bat is run … Read more

How to convert the value of %USERNAME% to lowercase within a Windows batch script?

Well, I was browsing for some syntax and stumbled upon this page. I know its old but I thought I’d take a break and give the brain a little kick. Here’s something a little shorter and manageable. This just “brute forces” all uppercase letters to lowercase letters without regards to whether the actual letter exists … Read more

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