Tmp or not to Tmp

Today I accidentally found solution for problem that annoying me for years (literally). And I would like to share it.

Problem

Problem was that I cannot print anything at my work from Microsoft Word and Firefox. I use Firefox as my main browser and sometimes (not that often) I have to print from Microsoft Word. And there is no error or similar. Just printer icon pops up for few seconds stating that there is nothing to print and that’s it. I can print from PDF viewer or from another browser but not from Firefox. And it was annoying me a lot. Few times I did something important in Firefox that I have to print, and I cannot open it on another browser due to specifics of web site. So, I have to capture screen and print it as picture.

As for Microsoft Word I have to save it to PDF and print from another application or ask co-worker to print it for me.

And it was not related to printer because I cannot print to PDF or XPS. And it was not related to computer because I got new clean computer and it has same issues.

I though it is related to our IT structure and asked IT admins to check and they found that Word prints only if you run it elevated and only suggested to replace computer again. So, I actually gave up and I thought it is something related to domain controller and my profile. After all it was not that critical.

But few days ago, from my home PC I contacted one company with hardware warranty and they asked me for proof of purchase. And Amazon have way to print invoice but after I tried to print invoice to PDF I got zero length file and no errors. I tried XPS and had similar issue. I sent them screenshot and today I had time to investigate that problem.

Investigation

Basically, there is pretty much nothing common between my work and home computers and it is more likely software issue. So, I tried to print some page to PDF from Firefox and this time I actually got “an error occurred while printing” error message. I checked Event Log and there is nothing happening at time when I tried to print. And next step was to search internet and I found that page: https://support.mozilla.org/en-US/questions/1106087. And I that it hit me.

Explanation

For good old DOS times there were two environment variables TEMP and TMP. They point usually to the same directory that will have temporary files that many programs have to create in order to work. Windows follows the same rule and for each user these variables points to %userprofile%\appdata\local\temp and it could expand to something like C:\Documents and Settings\ Goldfinger.Thunderball\Local Settings\Temp. Unfortunately, many applications were not able to handle space in temp directory path (well some still do). Many applications didn’t expect that long path. They were prepared to get 20 – 30 characters at most and crashed with longer paths. Also, some users where smart and put some funny characters (or characters from non-English language) and again application are failing. And also, there were (and still are) some applications that expects C:\Temp directory and fail to work with out.

So, I got used to create C:\Temp directory and change TEMP and TMP to point to that directory and everything was fine.

So, when I did read solution I tried to change TMP to what was default and after that Firefox starts to print to PDF without any problem. But surely path itself didn’t change anything. But what did? Directory permissions. There are two parts to that.

  1. When someone creates C:\Temp it will inherit permissions from C:\ and they are quite different from %userprofile%\appdata\local\temp.
  2. Also, when I created this directory I was elevated so it has even stricter permissions than usual.

To be honest I don’t know what exactly Word and Firefox are doing in C:\Temp that prevents them from working while other applications can create temporary files without problem, but they are doing something for sure. Maybe one day I will investigate it.

Solution

Because TEMP and TMP environment variables points to C:\Temp only in my profile, it is safe to apply all directory permissions from %userprofile%\appdata\local\temp to C:\Temp. I did that, and everything started to work magically.

I hope it will help someone.