Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I make my environment variable (set in batch file) visible in application executed right after setting this envvar?

Here's the scenario that I use:

  1. In my external script (not quite important here) I create Windows shortcuts to jpg files, with the target looking like:


    %MYPHOTODRIVE% should contain just a current drive letter.

  2. I start IrfanView using the following BAT script (script is located in the same directory as all the .lnk files):

    set MYPHOTOSDRIVE=%cd:~0,2%
    "c:\Program Files\IrfanView\i_view32.exe" "i:\private\photolinks\photo001.lnk"
    "c:\Program Files\IrfanView\i_view32.exe" /slideshow="%cd%"

The problem is that neither the single image, nor a slideshow (for the second call to IrfanView) is executed properly.

Shouldn't this "MYPHOTODRIVE" variable be expanded to a proper value upon Irfan execution? Doesn't it get the same environment as the parent script?

share|improve this question
(1) Look at the Properties dialog for your picture shortcuts. Do they still have %MYPHOTOSDRIVE%? If that variable is not set globally (for all of Windows, not just a single console instance), then Explorer does not use it. (2) Try adding a line after the set like echo %%MYPHOTOSDRIVE%% to see if it is correct. (3) I don’t think IrfanView can take a shortcut; it won’t resolve automatically. – Synetech Feb 6 '12 at 1:08
*1 Yes, all picture shortcuts have %MYPHOTOSDRIVE% instead of a drive letter. *2 Env. variable is set properly when I check it this way. *3 I was hoping that it would work the same as it does when calling another batch script from the first one. In this case this variable would be expanded to a proper value... – schedar Feb 6 '12 at 1:13
up vote 0 down vote accepted

The problem is that you are not passing an environment variable to IrfanView eg:

C:\> i_view32.exe %%myphotosdrive%%:\private\photos\photo001.jpg

You are passing it a .LNK file (which is binary). IrfanView does not know how to interpret shortcut files; it only handles graphics files and such.

Your best bet is to request that Irfan add the ability to resolve shortcut files (he is quite responsive and good at handling support questions and feature requests).

share|improve this answer
You're right. I've created a request here:… – schedar Feb 6 '12 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .