NVidia OpenGL display driver lost connection error troubleshooting

In recent operating systems and more recent games you may have encountered the following message every now and then.

Sometimes the message won’t show at all depending on your windows settings and or game.

“The NVIDIA OpenGL driver lost connection with the display driver due to exceeding the Windows Time-Out limit and is unable to continue. The application must now close.
Error code: 7″

nvidia_opengl_lost_connection_error

This is actually a good thing which prevents freezes of your whole operating system. In some cases however we want to workaround it by increasing the time before timeout. You can read more about this on Microsoft Support.

We do this by editing a key in the windows registry. For example I have to change this to 8 seconds or so in order to take high resolution screenshots in SpaceEngine.

Warning! Before proceeding you should know that setting this to a bad value could mess up things on your computer. Create a system restore point and backup your data!

NOTE! This affects all graphics programs and games on your computer. I recommend restoring the value after you’re done testing.

Proceed on your own risk!

Option 1: Right and select save as on any of the registry patches. Double click on them in explorer to install

TdrDelay-8sec.reg – TdrDelay set to 8 seconds (this should be enough for SpaceEngine)
TdrDelay-32sec.reg – TdrDelay set to 32 seconds (try this if error still shows)
TdrDelay-uninstall.reg – This removes the registry value which will use windows default. (Windows default is 2 seconds)

Option 2: Manually edit the registry

Open regedit.exe and navigate to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers

Create a new key DWORD32 and name it exactly TdrDelay
I tried 64 but it wouldn’t work for me even though I use a 64 bit OS.
Remember that this key name is cAsE sEnSiTiVe.

Double click on the key, choose decimal value and set it to the delay that you want.
I recommend trying 8 to 32. Delete the key when you’re done.

Here is a tiny gif animation. Please excuse the Swedish 🙂

TdrDelay

If you have any additional information to add or if I got anything wrong, please don’t hesitate to leave a comment!
Cheers


Robocopy sync multiple folders – to one location – batch script

From Wikipedia:

Robocopy, or “Robust File Copy“, is a command-line directory and/or file replication command. Robocopy functionally replaces Xcopy, with more options. It has been available as part of the Windows Resource Kit starting with Windows NT 4.0, and was first introduced as a standard feature in Windows Vista and Windows Server 2008.

This makes it a very useful simple syncing tool. The following is the script that I use to sync my laptop documents when I’m leaving the office. There are a lot of applications and tools for this but sometimes you just want a portable script.

Please note that this is a one-direction sync. It will not change or remove anything from the source folder.

robocopy-sync-unicode-folders

Instructions

  1. Copy and paste the following batch (*.bat) script into your favourite text editor of choice or notepad. (Not Microsoft word) You can also download it directly from here or here mirror. (You might have to right click and select save destination as)
    @echo off
    ::Unicode
    CHCP 1252
    echo %~dp0
    ::Remove old log file
    if exist "%~dp0\robocopylog.txt" del "%~dp0\robocopylog.txt"
    ::Ignore the following file types. You can add more separated by space
    set exclude=*.bak *.backup
    ::Go through each line in the folders.txt file
    for /f "skip=2 delims=" %%f in ('find /v "" %~dp0\folders.txt') do (
      ::Check if the relative path from current directory works 
      if exist "%~dp0\%%f" (
        ::Sync relative path
    		robocopy "%%f" "%~dp0\%%f" /v /xf %exclude% /mir /tee /fft /log+:robocopylog.txt
    	) else (
    	::Sync absolute path if relative didnt work
    		robocopy "%%f" "%~dp0\%%~nf" /v /xf %exclude% /mir /tee /fft /log+:robocopylog.txt
    	)
    )
    ::Wait for keyboard input before closing the window. Remove pause if you want it to close
    pause
    
  2. Save it where you want your backups to be stored (destination). Use whichever name you like. For example robocopy sync unicode folders.bat
  3. Create a new text file named folders.txt using any text editor and enter each folder that you want to make a backup off separated by a line break. (sources) Save the text file in the same folder as the batch script. Relative paths work too. Example:
  4. Run the script! The black window will stay open when it’s completed.
    With the above example the result would look something like this:

Notes

  • If source folders share the same name, they will be merged. Keep this in mind.
  • This is a one-direction only sync. It will not move or remove anything from the source folder.
  • If you don’t want the window to stay open when it’s complete remove the last line “pause” from the script.
  • A log file is saved for each operation in robocopylog.txt
  • You can add more files to exclude if you want, example: exclude=*.bak *.backup *.mp4 *.avi

VBScript Map Network Drives

This script will silently map specified network drives in the background and retry for a specified number of times with a specified delay before giving up. (Default: 10 retries per second for 120 retries)
You can change this by editing the script and changing:
delay = delay between each retry
timeout = number of retries

Using a batch command would also work but then you would see a black window popping up, hence the vb script.

Why?

In Windows 7 when you’ve mapped persistent network drives they can give error messages depending on different booting priority issues. This is a fairly common problem that doesn’t overall affect the functionality, it just adds an annoying pop up message on startup marking drives over with a red cross.

There are other workarounds that delay network before login or some such but that can cause other issues with services and this workaround was just simpler and quicker for me. This is just one example and with this simple script you can easily get rid of the message.

network drives error

Instructions

If you already have mapped drives (persistent) you need to disconnect them.

1. First step  – Download the file or save the script manually

Right click this link and select save as / save link and download the script (mirror) directly.

OR

Manually copy and paste the following text into your favorite plain text editor or windows notepad (not Microsoft Word) and save the file as MapNetworkDrives.vbs

'This script will silently attempt to map network drives of your chosing and retry doing so for 120 seconds
'If drive letters are already mapped the script will exit
'nirklars.wordpress.com
set shell = wscript.createobject("WScript.shell")
set filesys = CreateObject("Scripting.FileSystemObject")

'Change this to the number of retries you want before giving up
timeout = 120
'Change this to the delay between retries, in milliseconds 1000=1 second
delay = 100

function MapDrive(pathNetwork, driveLetter,loginCred)
	count = 0
	do
		if filesys.DriveExists(driveLetter) or count > timeout then 
			'msgbox "Drive exists"
			exit do
		end if
		commandString = shell.ExpandEnvironmentStrings("%WINDIR%") & "\system32\net.exe use " & driveLetter & ": " & pathNetwork & " /p:no " & loginCred
		'InputBox " "," ",commandString
		shell.run(commandString), 0, true
		WScript.Sleep delay
		count = count + 1
	loop
end function

'Copy and paste for each network drive to map
MapDrive "\\netgear\test1","Y","/USER:guest" 
MapDrive "\\netgear\test2","Z","/USER:guest" 
MapDrive "\\netgear\test3","W","/USER:guest" 

2. Second step – Edit the file

Edit the bottom of the file where it says MapDrive. Each line adds another network drive mapping so copy and paste for each drive you want mapped. Example:

MapDrive “\\netgear\test1“,”Y“,”/USER:guest

This example will map the folder test1 on a NAS server with the network name netgear with the drive letter Y.

3. Third step – Set it to start automatically when booting windows

If you’re on Windows 7 you can most probably just place it in your start menu startup folder.
Hold down the windows button and press R and type shell:startup and press enter to quickly open it.

shell-startup

On Windows 8 or more recent you can’t do that. Instead you must schedule a task to run on start up and login to launch the script. See instructions here.


AutoCAD font overrides

Here is how to properly override (replace) font’s globally in Autodesk AutoCAD.

Why replace?

Unicode fonts

Depending on your version of AutoCAD the nordic characters for ÅÄÖÆØ might not be working properly. This is usually caused by different versions of the same font’s. For some reason it seems, the characters ÅÄÖÆØ were removed from iso.shx

Fortunately they’re still available in isocp.shx and it’s perfectly fine to replace each font one by one in every drawing. This gets tedious though if you have hundreds of drawings to plot.

Better performance

Another reason might be to get rid of demanding true type fonts commonly used in drawings. If someone uses advanced font’s in drawings this will use up a lot more graphics memory slowing down performance.

demanding fonts

How to replace

Start by locating the file acad.fmp in your AutoCAD support folder. Depending on your version and the user account in Windows this will be stored in different paths.

acad_fmp_path

To quickly find your windows account profile folder you can copy and paste this into the explorer address bar and press enter:

%appdata%\Autodesk\

Check the year release version of Autocad you have installed. Is it 2010, 2014, 2016 or some other year? If you’ve got an AutoCAD subscription you might have several versions installed. If you have 2016 you can copy and paste this into the explorer address bar and press enter:

%appdata%\Autodesk\AutoCAD 2016\R20.1\enu\Support

If you’re hopelessly lost attempting to locate this folder you can use a shortcut built into AutoCAD by clicking File -> Plot Style Manager. This will open the adjacent path where your plot styles are stored.

plot style path

Editing acad.fmp

Before proceeding, once you’ve located acad.fmp make a backup copy of it, just in case. Call it Copy of acad.fmp or something similar.

Open it using Notepad or any other plain text editor. (Not Microsoft Word). Once open it should look something like this:

acad.fmpACAD2016 original: acad.fmp (mirror)

Each new line in this file means one font replacement operation. The syntax for instructing which font to replace is separated by a semicolon ;

The original source font;The font which to replace it with

For example if we want to replace iso with isocp we add the following line. (This is the workaround for nordic characters to work.)

iso;isocp.shx

acad.fmp_edit Edited: acad.fmp (mirror)

For this to have any effect you need to restart AutoCAD completely. All done!

Resource intensive fonts

Consider adding more resource intensive fonts.

And don’t forget the pesky Comic Sans MS! We don’t want that in our drawings do we? 😉

acad.fmp_edit2 Edited 2: acad.fmp (mirror)

End notes

Please keep in mind that replacing font’s will cause external references XREF fonts to change as well. This will cause formatting issues, especially if the new font is larger than the original.

This is important to note in case something goes wrong and you’ve been accidentally messing with someone else’s drawing. To avoid this then restore the original acad.fmp file and restart AutoCAD before plotting.


Add scaled timestamps to photos using ImageMagick

Here is one way to add timestamps quickly to lots of photos using open source tools and a script.

The image editing is done using ImageMagick  convert.exe and identify.exe

ImageMagick is a free to use open source collection of command line tools for image editing, identifying, manipulation and much more.

stamp

This script will go through all JPG, JPEG, GIF and PNG files inside the current folder, make copies of them in a separate folder and add date and time saved (burned) into the image. The operation is lossy hence it only modifies copies of the files. Date and time is retrieved from the metadata tag Exif.Image.DateTimeOriginal. If the images lack this tag they will be stamped “No timestamp”.

The timestamp font size and placement on the photo will scale in percentage according to the width and resolution of the photo.

If you want to change colors or such you will need to edit the script manually. Here are some examples of photos I’ve taken with added timestamps:

If these kind of timestamps are good enough for you, you’ve found the right post!

Instructions

timestamp

Option a) – quick

1. Download the script (mirror) together with portable ImageMagick convert.exe and identify.exe
MD5: a5363bef4aafbe979dcac875f7f2e263

2. Extract all files in the folder where you keep the images that you wish to add timestamps to

3. Double click on add timestamps.bat to start the process.

A black window should pop up showing the image conversion process in ImageMagick.

timestamp

4. When done you should see a folder named stamped with copies of the files with added timestamps!

Option b) – manual

1. Download ImageMagick from the windows portable edition here and place convert.exe and identify.exe in the same directory where you place the script. Alternately you can use the files supplied in the download above.

2. Copy and paste the code from below into your favorite plain text editor like notepad, notepad2 or notepad++

3. Save it with whichever name you prefer as long as you end the name with the file extension .bat for example add timestamps.bat

4. Double click on the bat file to start the process!

Batch script to copy and paste

@echo off & cls
rem enable variables referencing themselves inside loops
SetLocal EnableDelayedExpansion

rem optional settings
set fontcolor=#FFD800
set fontoutlinecolor=#000000
set fontstyle="Arial-Bold"

rem create a new folder where the stamped images will be placed
mkdir stamped

rem loop through all jpg png jpeg and gif files in the current folder
for /f "delims=" %%a in ('dir /b /A:-D /T:C "%cd%\*.jpg" "%cd%\*.png" "%cd%\*.jpeg" "%cd%\*.gif"') do (
	rem retrieve image date and time
	SetLocal EnableDelayedExpansion
	for /f "tokens=1-2" %%i in ('identify.exe -ping -format "%%w %%h" "%cd%\%%a"') do set W=%%i& set H=%%j

	rem retrieve image timestamp to perform size and distance calculations on
	SetLocal EnableDelayedExpansion
	for /f "tokens=1-2 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k
	
	rem set timestamp to no timestamp if there is no timestamp
	if "!timestamp!" == "" (
		set timestamp=No timestamp
	)
	
	rem print some information about the process
	echo %%a is !W! x !H! stamp !timestamp! ...

	rem set timestamp size to a fourth of the screen width
	set /A timestampsize = !W! / 3

	rem set timestamp offset distance from side of the screen
	set /A timestampoffset = !W! / 20

	rem set timestamp outline relative size
	set /A outlinewidth = !W! / 600

	rem echo !timestampsize! !timestampoffset!
	
	rem create a custom image with the timestamp with transparent background and combine it with the image
	convert.exe ^
	-verbose ^
	-background none^
	-stroke !fontoutlinecolor! ^
	-strokewidth !outlinewidth! ^
	-font !fontstyle! ^
	-fill !fontcolor! ^
	-size !timestampsize!x ^
	-gravity center label:"!timestamp!" "%cd%\%%a" +swap ^
	-gravity southeast ^
	-geometry +!timestampoffset!+!timestampoffset! ^
	-stroke !fontoutlinecolor! ^
	-strokewidth !outlinewidth! ^
	-composite "%cd%\stamped\%%a"

	endlocal
	endlocal
	echo.
)
endlocal
echo Complete!
pause

More info

I also wrote a VBScript version of this operation as well but It would have a lot of black windows popping up being quite annoying.

Unfortunately hiding windows gets trickier when using VBScript when you also need to retrieve the return value from command line utilities.

If you want to check out the vbscript anyway you can still get it here (mirror) (git)


Bypassing European ‘Right to be forgotten’ censorship of Google

Update 2016: Using google.com/ncr to bypass the filter no longer works. Google now censors EU results if you’re in the EU ISP IP range. You have to use a US proxy.

This post is not related to any software but rather in opposition of censorship.

Problem

If you’re in the EU and searching using Google you may have encountered this notice at the bottom of some pages:

censorship

If you did not know there is a European Union law that allows people the “Right to be forgotten” which specifically applies to Google search.

While it may sound like a good idea in some regards, like perhaps false accusations; in practice it forces search providers to act as judges for what is appropriate.

This can have the exact opposite effect for actual perpetrators which makes this legislation really flawed.

Workaround

There are many ways to bypass such filters, one of them by using another search engine or any kind of vpn or proxy server. There is also a hidden option in Google:

http://www.google.com/ncr

The abbreviation NCR stands for – no country redirect.
This option will return US search results.

More information

I won’t go into this into this law in any more detail but feel free to read more about the “Right to be forgotten” and controversy related to it here: