Why doesn't the windows registry know how to interpret or expand %temp%?

2

1

I have a registry entry in the Run key as follows:

type = REG_SZ, value = test, data = %temp%\test.exe

When I reboot my machine test.exe does not run, but if I do the full path of the temp folder (something like "C:\Documents and Settings\XPMUser\Local Settings\Temp") then it does run it upon reboot.

What's up with this?

I also tried type of REG_EXPAND_SZ but it still didn't work.

Brian T Hannan

Posted 2011-03-11T20:05:24.017

Reputation: 891

1Using REG_EXPAND_SZ should work for the Run key. Try opening a command-prompt and running the command set temp. Does it show the variable expanded? Try opening an elevated command-prompt and repeat. Does it expand the variable now? – Synetech – 2011-03-11T20:18:49.887

Thanks guys, it turns out it was a mistake on my part. I reverted my VMWare image and now it's working fine. – Brian T Hannan – 2011-03-11T20:49:09.143

If you solve the problem on your own: either post your own answer describing the solution, or close the question as "no longer relevant". – user1686 – 2011-03-12T20:20:58.870

Answers

1

The registry is just a database of information - it is not an application which can 'interpret' its own content.

I can see no reason why this shouldn't be possible. Maybe you could create a small batch file that echos %TEMP% to a file at bootup to see what, if anything, is in there?

Majenko

Posted 2011-03-11T20:05:24.017

Reputation: 29 007

1Actually, the environment in Windows is initialized by the session management subsystem which occurs early in the boot sequence. This means that all variables should be available for expansion by the time that Explorer runs and launches the items in the Run key (which definitely knows to run ExpandEnvironmentVariables() on the values). – Synetech – 2011-03-11T20:17:46.283

That's good to know – Majenko – 2011-03-11T20:47:37.057

1

What about surrounding the data in quotes?

Mark Sowul

Posted 2011-03-11T20:05:24.017

Reputation: 2 877

Good point. Explorer uses ShellExecute to start the "Run" entries, to allow for command arguments, etc.; it's possible that it would attempt to start C:\Documents in this case. – user1686 – 2011-03-11T20:32:29.633

Not likely. Brian said that he is using the temp variable which is the system temporary directory, which is usually in C:\Windows\Temp (which has neither spaces nor long names). The users’ local temp directory is stored in the tmp variable. So unless he specifically changed the system temp-directory variable to point to a directory in his own folder, spaces should not be an issue. – Synetech – 2011-03-11T20:34:38.783

@Synetech: In all systems I have seen, both %TEMP% and %TMP% point to the user's temporary directory. – user1686 – 2011-03-11T20:36:35.463

Strange. Check the registry and you should see that temp is defined in HKLM with a reference to systemroot and tmp is defined in HKCU with a reference to localappdata. – Synetech – 2011-03-11T20:46:29.177

1@Synetech: I checked Windows 2008 Server, Windows XP Pro and Windows 2000 Pro: Both TEMP and TMP are defined per-user (HKCU\Environment pointing to user profile subdirectory) and system-wide (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment pointing to %SystemRoot%\Temp). – user1686 – 2011-03-11T21:12:58.240

1That sounds about right more or less. The user version overrides the system one. I suppose programs like installers that need to work outside the user’s circle get the system-level variables. (It seems like more work than simply using different variables, but then that’s yet more backwards-compatibility for you.) – Synetech – 2011-03-12T00:01:51.230

@Synetech: The system-wide Temp directory is mostly for services running as NT AUTHORITY\SYSTEM. (I haven't checked Windows Installer, but it seems like it loads the user's environment. By the way, about a half of the services run under NT AUTHORITY\LOCAL SERVICE or NETWORK SERVICE accounts, which have their own temp directories too.) – user1686 – 2011-03-12T20:26:30.770

0

Enclose your %temp% variable in quotes. The space in the path may be throwing something off.

data = "%temp%"\test.exe

Jay Teal

Posted 2011-03-11T20:05:24.017

Reputation: 1

Spaces should not matter in the context of a Run key entry unless there are command-line arguments, which the question does not include. Trust me, I’ve experimented. – Synetech – 2011-03-11T20:42:17.310

True, unless there happens to be a "C:\Documents"... (I believe Explorer warns if a "C:\Program" exists along with "C:\Program Files".) – user1686 – 2011-03-11T21:01:54.600

0

Verify that %temp% even points to the folder that you think it does.

Synetech

Posted 2011-03-11T20:05:24.017

Reputation: 63 242

1Where are you finding these mysterious machines whose user accounts expand %temp% to C:\Windows\Temp? 1998? – Mark Sowul – 2011-03-12T00:42:38.887

User accounts don’t expand it to the system temp folder, they expand it to the local folder. Users have their own environment variables that override the system-wide one. – Synetech – 2011-03-12T04:36:40.187