Setting and changing Vars in batch files

I thought this was an easy project, but it seems to be one without a direct [read that as 'simple'] answer.

"ALL" I want to do is to set a variable for a browser, and then be able to change the browser that is attached to that variable via batch file so that [in the next line??] I will be able to use the 'new' var as a launching element. Such as:

cBrows = "C:\Program Files (x86)\Internet Explorer\iexplore.exe"
cBrows = C:\WinApps\Comm\Internet\Browsers\Firefox\firefox.exe

It didn't work under DOS with either "set" or "xset."

Is this really that difficult?

Chuck Billow
Steve, that part I get. But, when I checked my batch file, it still didn't work. BTW, the only reason I would use "dos" commands is that TCC reads dos commands, but dos doesn't always read TCC commands. That being said, if I want to be able, via batch commands / file, to clear a user variable and then set it to some other value, shouldn't that be possible, even easy?

If I have a bunch of web pages, and today I want to access them all via Chrome [var = gChrome], but then, maybe tomorrow I want to use Firefox, and then the next day..., how the heck would I construct it so that, whether they were running DOS or TCMD, it would work?

This has certainly shown me how little I know!

Cuck, it was Vince who got the chance to answer you before.
DOS=Disk Operating System, not a command processor. PC-DOS and MS-DOS included COMMAND.COM as their command processor; JP Software competed with 4DOS.COM, which grew into 4NT and finally into TCC.

Did you initialize the cbrows variable with the SET command? Unlike any of the *nix command processors ("shells"), the command must be explicit to set the value of a variable iCOMMAND.COM and all its descendants:
set cBrows = C:\WinApps\Comm\Internet\Browsers\Firefox\firefox.exe

BTW, 4DOS (which is now freeware) includes the ALIAS command...
Steve, are you, by saying that in the command must be explicit, saying that in the input line of

cBrowser = %ieBrows%

won't work...that you cannot nest variables in

If that is in fact what you are saying, that is why I cannot get this to work.

As for aliases, I use aliases -- in tcmd / tcc windows. I'm not sure I see how their use would apply though to calling different browsers in Windows 7 programs.

Steve, are you, by saying that in the command must be explicit, saying that in the input line of

cBrowser = %ieBrows%

won't work...that you cannot nest variables in
I wouldn't that exact line to work anywhere. Did you mean

set cBrowser=%ieBrowser%

I don't know about nesting variables in
Steve, are you, by saying that in the command must be explicit, saying that in the input line of

cBrowser = %ieBrows%

won't work...that you cannot nest variables in
No. Firstly, the paragraph below applies in COMMAND.COM, CMD.EXE, 4DOS.COM, 4NT.EXE, TCMD32.EXE and TCC.EXE alike. In the various Unix/Linux style shells, to assign a value to a variable in a statement you do not need a command verb, the statement of the form
is automatically an assignment. Cf. in all of the PC-DOS/MS-DOS/Windows command processors listed you need the SET verb:
SET variable=value

OTOH the value can be a complicated expression in all of them; much more complicated in the JPsoft products than in the MS products.

The other main difference between the Unix-type shells and the MS-style command processors is that variables are not automatically evaluated (expanded in MS and JPsoft parlance), you must explicitly signal the command processor to do it using the percent sign (%).

Note that in all of these command processors a variable exists only in the single instance of the command processor in which defined, and inherited by those instances of command processors that are started from that instance or from its children. every program inherits all of the variables of its parent program, unless it is started specially (in 4nt or TCC with the START /I command).

To set variables in a command processor so that they are available outside its process tree you can use registry variables. In 4NT and TCC you can use the SET command to do this, with one of the options /D, /S, /U or /V. hese are available to any process that checks them.

As for aliases, I use aliases -- in tcmd / tcc windows. I'm not sure I see how their use would apply though to calling different browsers in Windows 7 programs.
The aliases would be used from the command processor to select which browser to start. Using global aliases the choice is instantaneously changed for all JPsoft command processor instances, so you can control in one TCC instnace which browser any other instance would use.


Scott Mintz
May 20, 2008
Solon, OH, USA

I think we have a misunderstanding in what you are trying to do. If the goal is to have a common "verb" for launching different browsers from the command line, an alias is the easiest and best solution.

alias IE=%LOCALAPPDATA\Google\Chrome\Application\chrome.exe
alias IE="%ProgramFiles\Internet Explorer\iexplore.exe"

Then typing IE on the command line launches the selected browser. On the other hand, if the goal is to have a common "noun" that can be referenced from the command line as well as from other executables, then an environment variable is the better option.

SET IE=%LOCALAPPDATA\Google\Chrome\Application\chrome.exe
SET IE="%ProgramFiles\Internet Explorer\iexplore.exe"

To launch it from the command line you would type %IE. Or %IE% in CMD. To reference the IE variable from another executable, you would use that application's mechanism for getting environment variables. Within MAKE utilities it would be $(IE). From a C/C++ application you could use getenv().
Scott / Steve / Vince;

While I am learning a heck of a lot, I'm not sure I totally understand all the implications as they relate to my initial desired task.

I can see I am being at best vague, and at worst... In either case it is taking up a lot of time from you all. For that I apologize.

Let me come at this from a different vantage point:

There are three users that share a computer. On that computer there are a set of some 50 - 60 web site links.

As the PC's default browser, all have agreed to settle on Firefox. As luck would have it, each of the users however, has a different browser preference -- but only for that specific set of links.

On the one hand, I could set up three sets of links, with a different browser assigned for each set. That, in my mind at the time, seemed silly. Why not instead, I thought, link the set of sites to a variable, which then could be defined to "any" browser?

Again, I realize that I could do it via a set command in each user's login script, assigning the specific browser to a variable [like myBrowser], and then linking that variable to the set of site shortcuts [%myBrowser%].

But what if a user that was set up to have Firefox, for instance, for that set of links decided instead to have Chrome for that set? Could / would there be a way to change the variable dynamically [via batch file? Alias definition?], instead of changing the login script, logging out, and then logging back in?

As a result of the info you all have shared, I [now at least] understand that there is no one way that will work on all machines and all OS's.

That part, for this circumstance at least, is easy. It's a Windows 7 [Ultimate] machine that has TCMD installed. I do wonder if a solution here work the same if the machine were "upgraded" to Windows 8?

I have never checked, but isn't the default browser a per-user setting? IMHO, it should be.

If so, your collection of links need not point to any browser. They can be mere internet shortcuts (http://...).
I found this, regarding the question of per-user default browser on Win7.

Each user’s default can be chosen by using the built in utility described below, but it does require the user to log into that specific account.
1. Log into the user account
2. Click Start
3· Click Default Programs
4· Click Set program access and computer defaults
5· Expand Custom
6· Select the Internet browser you want to use under Choose a default web browser:
7· Click OK
Guys, I knew that the users could each set their own default browser. But what if I want to keep the default [as Firefox] but then open that specific group of links with a separate browser? Hence the setting the variable via user login...but then, if the user wants a different browser temporarily for that set of links?
If (with TCC) you (for example, at any time)
SET /U MyBrowser=iexplore.exe
Explorer will know about it and that variable will be in Explorer's environment (change it the same way) and given to every program Explorer subsequently starts. But as far as I can tell, Explorer will not let you specify "%MyBrowser%" in the target of a shortcut.
[Window Title]
Problem with Shortcut
The name '%mybrowser%' specified in the Target box is not valid. Make sure the path and file name are correct.
I don't think shortcuts with variable targets will work.
As proof that Explorer knows what %MyBrowser%" means, I went to Start\Run (Win+R) and typed "%MyBrowser%" ... Explorer opened IE.
Vince, if you set it up using the "typical" means for an internet shortcut, it won't work. If however, you set up a "regular" shortcut, and then edit it to call the [var] browser, and a link, it works fine.

The attached is actually a shortcut that I had to change the extension from lnk to txt so that it would upload.


Vince, if you set it up using the "typical" means for an internet shortcut, it won't work. If however, you set up a "regular" shortcut, and then edit it to call the [var] browser, and a link, it works fine.

The attached is actually a shortcut that I had to change the extension from lnk to txt so that it would upload.
That's exactly what I tried to do. I made (regular) shortcut (.LNK) to notepad then, in it's properties dialog, tried to change the target to %MyBrowser%". That's what gave me the message box.

Edit the shortcut with what? Are you using some third party tools to do all this? What's the TXT file you posted? That file contains strings like these (stuff I'll stay away from). Who knows what's actually happening when you click on one of those things
\\OLFOGEY\Host-Root WinApps\Comm\Internet\Browsers\Pale Moon-x64\palemoon.exe
Ultimate Windows Tweaker (C:\WinMgmnt\System\Tweakers) 
C:\WinMgmnt\System\Tweakers\Ultimate Windows Tweaker\Ultimate Windows Tweaker.exe
Well, I got it to partially work. If %MyBrowser%" (in Explorer's environment) is a fully-qualified path to an EXE, then the shortcut's properties dialog accepts it. So I
v:\> set /u mybrowser=l:\Firefox\firefox.exe
That caused Explorer to get the MyBrowser variable and a newly made shortcut to %MyBrowser% worked immediately, starting FireFox. Then I
set /u mybrowser="C:\Program Files\Internet Explorer\IEXPLORE.EXE"
Explorer immediately changed its notion of %MyBrowser% (evidenced by giving %MyBrowser% in Start\Run).
But the behavior of the shortcut did not change until it (the shortcut) had somehow been "refreshed". The only way I could refresh it was to open its properties, make and undo some tiny change, then say OK.

So "SET /U lfbrowser=(full path\exe)" will do much of what you want (change Explorer's notion of %ifbrowser%). But getting that to propagate to how Explorer handles shortcuts is a problem. Guess: Explorer probably caches shortcut info and only changes its cache when it knows you've edited the shortcut. I'll look a bit for a workaround but I'm not optimistic.

These did not work to refresh the shortcut: F5, TOUCHing the LNK file, renaming/renaming_back the LNK file, moving/moving_back the LNK file.

Using "SET /U lfbrowser=(full path\exe)" worked, except that, as you told me, the path must be literal.

Assuming the machine has TCMD installed, is there a way to use aliases in place of variables for the different literal commands [browsers]?

I'll check out "SET /U lfbrowser=(full path\exe)". Was the command executed in DOS or TCMd / TCC?
Explorer.exe is the process that resolves shortcuts. So the variable %lfbrowser% must be in Explorer's environment. When you "SET \U (anything)" TCC (only TCC does this) writes info to the registry key HKCU\Environment and sends a message to all interested parties that it has done so. Only Explorer.exe is smart enough to act on this message by updating its own environment. So TCC (only) provides a way of changing Explorer's idea of what %lfbrowser% means.
So then I could at least set up shortcuts for TCC to switch browsers -- or a set of Reg entries? And you say "only TCC" not TCMD? I had thought that TCMD was TCC at it's core?
You could set up shortcuts for TCC to change the value of %lfbrowser% and let Explorer know. But as I said before, Explorer sometimes doesn't use the new value of %lfbrowser%. I have also seen instances where Explorer (or someone) actually changes the target of the shortcut from %lfbrowser% to the literal text represented by the variable. I don't think you can get this approach to work perfectly.

Unless you have started another program on purpose, TCC is the program running in TCMD tabs. You don't give commands to TCMD; you give them to TCC (or whatever other program is running in the TCMD tab).
No, TCMD is more like Windows Explorer, a graphicla user interface, with tabs for different concurrently active textual user interface (console) programs. TCC is the command processor. You can run TCC in its own window, without activating TCMD (as I do), or in a TCMD tab. I also have many desktop shortcuts which use a TCC window for changing system configuration (e.g., screen resolution, screen saver timeout, etc.) which close themselves when the job is done.
This is really starting to annoy me. I have a few sites that don't work well with FireFox. I'd like to just right-click on the .URL file and choose "OpenWithIE". I wrote a little program to do it but it's turning out to be a nightmare trying to get it on the context menu for .URL. First, in HKCU\InternetShortcut (associated with .URL), the "Shell" key is owned by TrusterInstaller (god knows why) so I had to take ownership of it before I could write there. Then I tried the standard stuff ... subkey: "OpenWithIE" ... subsubkey: "command" ... @ = my_app ... It doesn't show up on the context menu. Does Win7 have the (good ol') dialog where you can define verbs and actions for file types? I couldn't find any such critter.

So I found a one-line REG file that adds "Open with" to InternetShortcut; it worked on one of two computers. On the computer where it worked, if I used it to say "open this .URL with Internet explorer and **don't** always do this", it opened in FireFox.

Try to associate/ftype .URL with a TCC batch file, which checks the URL against its list of IE - only URLs; if found, explicitly launch IE, else use the default browser. In TCC you could, of course, use an executable extension...
What a kludge! I found the problem ... something called "UserChoice" (know much about it?). In HKCU there's an area where "UserChoice" things are recorded. Even though FireFox is my default browser (and is used to open *.URL), *.URL was listed as UserChoice = IE.AssocFile.URL. The IE.AssocFIle.URL key was identical to the InternetShortcut key right down to the "open" action (a DLL call which no doubt checks what the default browser is). I was putting my verb/action in the InternetShortcut key. When I got rid of the UserChoice thingy, it worked fine.

So maybe I have a pretty good solution to CWB's problem. I wrote a trivial (but so far robust enough) app to use here:

HKCU\InternetShortcut\Shell\OpenWithIE\command\@ = g:\uty\browsewith.exe iexplore "%1"
HKCU\InternetShortcut\Shell\OpenWithFireFox\command\@ = g:\uty\browsewith.exe firefox "%1"
and/or ... whatever.

You only have to give it enough info about the browser so Explorer knows what it is and "iexplore" and "firefox" (the only two I tried) are sufficient (probably because of the AppPaths key).

Here's the little app I wrote in case anyone wants to play similarly, or suggest how it might fail. .URL files are in the INIfile format which makes it easy to get the URLs out of them. With no C library or other baggage I get a tidy little 3K EXE out of it.
#include <Windows.h>
// BROWSEWITH <browser> <file.url>
// HKCU\InternetShortcut\Shell\OpenWithIE\command\@ = browsewith.exe iexplore "%1"
// subsystem is windows
    INT argc;
    WCHAR szURL[1024], **argv = CommandLineToArgvW(GetCommandLine(), &argc);
    if ( argc == 3 && GetPrivateProfileString(L"InternetShortcut", L"URL", NULL, szURL, 1024, argv[2]) )
        CoInitializeEx(NULL, 0);
        ShellExecute(NULL, L"open", argv[1], szURL, NULL, SW_SHOW);
Chuck, the complicated stuff above is not mine, it's from Vince, and it relates to some Windows 7 "feature" which is either NOT documented, or is at most scantily documented. In other words, my pet peeve: your PERSONAL COMPUTER (PC) being taken over by Microsoft as if it were owned by Microsoft. Remember the days when full documentation was part of all software, whether application or operating system?