Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
1  
Using 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 Mar 11 '11 at 20:18
    
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 Mar 11 '11 at 20:49
    
If you solve the problem on your own: either post your own answer describing the solution, or close the question as "no longer relevant". –  grawity Mar 12 '11 at 20:20

4 Answers 4

What about surrounding the data in quotes?

share|improve this answer
    
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. –  grawity Mar 11 '11 at 20:32
    
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 Mar 11 '11 at 20:34
    
@Synetech: In all systems I have seen, both %TEMP% and %TMP% point to the user's temporary directory. –  grawity Mar 11 '11 at 20:36
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). –  grawity Mar 11 '11 at 21:12
1  
That 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 Mar 12 '11 at 0:01

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?

share|improve this answer
1  
Actually, 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 Mar 11 '11 at 20:17
    
That's good to know –  Majenko Mar 11 '11 at 20:47

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

data = "%temp%"\test.exe

share|improve this answer
    
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 Mar 11 '11 at 20:42
    
True, unless there happens to be a "C:\Documents"... (I believe Explorer warns if a "C:\Program" exists along with "C:\Program Files".) –  grawity Mar 11 '11 at 21:01

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

share|improve this answer
1  
Where are you finding these mysterious machines whose user accounts expand %temp% to C:\Windows\Temp? 1998? –  Mark Sowul Mar 12 '11 at 0:42
    
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 Mar 12 '11 at 4:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.