Tag Archives: Batch file

Creating Symbolic Links

I’ve been meaning to create a post about symbolic links and how to set them up, the benefits of them, pros and cons, however I’ve not had the time and I might just come back to this post one day, however it’s been a while and I think it’s worth just starting and leaving it where it is.

I sometimes reformat my Windows drive or as you do, upgrade to say another drive. Backing up your files is one thing, but have you ever thought, what about just using scripts to run once you re-install everything to point to the files so it’s almost plug and play?

So for example, in this situation we have the Steam userdata folder that resides in the Program Files within the C drive. Setting up a symbolic link to then automatically have that folder divert to a location on say a Steam dedicated drive, would mean no need to ever do large copies, but to just run the script after a reformat and you’re good to go. Especially handy when you forget to make a back up and reformat your Windows anyway!

This also comes in handy when the times your drive fails, however that doesn’t mean the drive you’re creating the link to doesn’t fail, make sure you have a plan for that.

Anyway, here’s the way to do it:

Step 1, run command prompt)

Start Command Prompt. Press start, type “command prompt”, right click on it and run as the administrator.

Step 2, copy paste your symbolic link)

You can just type “mklink” to get a list of details on what each parameter does. In this case we’re going to link one folder to another.

mklink /J “C:\Program Files (x86)\Steam\userdata” “D:\Steamuserdata”

And that’s it, we’re done.

I did a quick Google search to find more details on it, Microsoft have a page on symbolic links, you can find that here.

Uplay likes to save your screenshots to C:\Users\xxxxx\Pictures\Uplay another idea would be to divert those to your preferred location.

Combine PDF files with a context menu option

I needed a way to quickly combine two or more PDF files without having to run a program or click mutiple times. This solution basically allows you to right click and automatically combine your PDF files then delete them once it’s finished combining.

First download a program called pdftk, once installed head over to where you actually installed it, copy two files; “pdftk.exe” and “libiconv2.dll” to a new folder (preferably where you will not accidently delete it).

Create a new text file and rename it to “PDF Combine.cmd”, edit the batch file and copy paste the below code:

@echo off
setlocal enabledelayedexpansion

for /f “tokens=2 delims==+-” %%i in (‘WMIC OS Get LocalDateTime /value ^| findstr “=”‘) do (
set _Date=%%i
set YY=!_Date:~2,2!
set MM=!_Date:~4,2!
set DD=!_Date:~6,2!
set HH=!_Date:~8,2!
set MIN=!_Date:~10,2!
set SS=!_Date:~12,2!
)
set today=20%YY%-%MM%-%DD%-%HH%%MIN%%SS%

FOR %%A IN (%*) DO (set command=!command! %%A)
D:\pdftk\pdftk.exe %command% cat output “%~dp1CombinedScan_%today%.pdf”

del %command%

The output file names for mine is “CombinedScan_DATE&TIME.pdf”. Make relavent changes preffered to you and save.

Now we want to set up the context menu for it so you can right click on files.

  1. Right click on your “PDF Combine.cmd” file, create a shortcut.
  2. Press your Windows key + R to bring up your run dialog. Type “shell:sendto”, which should open up your Windows SendTo folder. Move your shortcut you just created to this folder and feel free to rename your shortcut to whatever you prefer, I personally named it “Combine PDF’s”.

Now go ahead and test your automated method out. I recommend you use some spare PDF’s that are backups just in case you did something wrong. If you prefer to just skip downloading and copying the files, I’ve done that already and made a zip folder for you below.

Download pdftk.

How to fast switch between resolutions using a batch file.

Here’s a quick way to switch between Windows desktop resolutions using a batch file and an executable file. I needed to do this in order to have a better overview in the game Age of Empires HD (on Steam). Let me visually show you what I mean. Have a look at the screenshots below, you can clearly see a more broader view as you up the resolution.

For some reason the viewing distance is different to the one in the original game.. A few years ago I tested to see if there is a difference in resolution compared to the old Age of Empires and there is so they have in fact made your viewing distance closer. As someone who’s played Age of Empires for a long time this was a problem for me. Now in the original you could change your resolution so simply enabling DSR Factor via your graphics control panel and changing the resolution in-game could resolve this issue for me, in this version the ability is not there (I assume poor development). Anyway, you will first need to enable DSR Factor, I currently prefer x1.75 as shown below.

Then you’ll need to download the file below. Tweak the resolution settings for what you prefer and run the game. If you have the option you can play around with the smoothing, essentially it’s anti-aliasing between the pixels so it doesn’t look pixelated due to the difference of your monitors resolution capability and what’s being scaled.

Now I was under the impression that a batch file can’t actually do this (on its own), I still think this is the case, but with simple help from a file you can still achieve it. The benefits of this way is you can change your preferred resolutions and simply run the batch file with as less clicking as possible, while an executable would require a bit of extra clicks.

At the time I could not find the source code for QRes (and I downloaded it from a separate site) so I did a virus scan on it – here’s the result. Secondly I used Sandboxie and launched the file in a sandboxed environment and looked at what – if any – files were executed along with it.. It left zero trace and the file size also indicates to me it’s pretty simple.

Now here comes the actual batch file.

QRes.exe /X 1920 /Y 1080

Yup, that’s it. So in the folder there is the ‘QRes.exe’ file, then there’s ‘RC 1920×1080.bat’ and ‘RC 2560×1440.bat’ files which I run to switch between the resolutions. All these files must be in the same folder for it to work and by the size of the QRes.exe file it looks to just simply run based on the resolution that’s provided in the batch.

Download Resolution Changer version 1.0 here.

 

Batch file – How to simply get yesterdays date (or any date) from the current computer date

Batch files are a nice and simple way on Windows to create one click solutions for tasks that you do on a regular basis. In my case, I wanted to find a quick and simple way to create a file I create on a daily basis and add the current date on it when I create it at the same time, of course as quick as possible.

I have a master file I want to copy it from, so with that I do:

@ECHO OFF
COPY “C:\Users\Savas\Desktop\Testfolder\masterfile.txt” /y
ren “masterfile.txt” “File1 – %date:/=.%.txt”

There’s obviously many ways to do this above so you can choose your way suited for you.. The result will basically be creating a file in the same folder as the .BAT file I created, it will name the file “File1 – date.txt” Because my computer date is set to 27/04/2015 standard (you can find this out by simply doing “echo %date%” and the result should tell you your date format. Simple!

Now what about yesterdays date, as far as I can find, there doesn’t seem to be a simple one line way to just do yesterday date.. So we have to set some variables and have the batch file get the date in DD format then minus off one day and then join the date back together.

set yyyy=%date:~6,4%
set mm=%date:~3,2%
set dd=%date:~0,2%

@set b=1
@set /a c=%dd%-%b%

COPY “C:\Users\Savas\Desktop\Testfolder\testfile.txt” /y
ren “testfile.txt” “File 2 – %c%.%mm%.%yyyy%.txt”

The %dd% takes the date and then takes off all, but the DD format. So instead of having 27/04/2015, we end up with just 27. Then “@set /a c=%dd%%b%” line simply takes the number 27 and minuses the number in the “@set b=1” variable, and in this case it’s “1” so we end up with the result in %c% declaration. Put the month and year and we have the date for yesterday!

Of course if you’re using these batch files on separate systems and these systems have different date formats, you’re going to reach some minor issues and that means you’ll need to be more specific with your date formatting. In my case, 6,4% takes a sub string, starting at position 8, and keeping 4, which is 6,4.

27/04/2015

In my case, I don’t have this issue, I don’t need my batch file to be some complicated and long winded method to pull the date and when I create my file, I will see if the date is wrong immediately. I hope this helped.