The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,482 other followers

Find an installed tf.exe, then run it with the command-line parameters specified.

Posted by jpluimers on 2015/04/30

Often I want to execute a TF.exe from the console, but don’t have the Visual Studio environment variables setup. Most of the times I want to run TF.exe from the most current Visual Studio installation, hence this TF.bat file figures out the location of it, then runs with the parameters passed to TF.bat:

@echo off
IF /I %PROCESSOR_ARCHITECTURE% == amd64 goto :x64
IF /I %PROCESSOR_ARCHITEW6432% == amd64 goto :x64
goto :x86
:: OS is 64bit
set vsBaseKey=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\
goto :findTF
:: OS is 32bit
set vsBaseKey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\
goto :findTF
set SupportedVisualStudioVersions=8.0, 9.0, 10.0, 11.0, 12.0, 13.0
for %%v in (%SupportedVisualStudioVersions%) do (
for /f "usebackq tokens=2* delims= " %%c in (`reg query "%vsBaseKey%%%v" /v InstallDir 2^>NUL`) do (
set tfExe=%%dtf.exe
if "%tfExe%"=="" ( echo no TF.exe found ) else (
if not exist "%tfExe%" echo not found: "%tfExe%"
if exist "%tfExe%" "%tfExe%" %*

view raw


hosted with ❤ by GitHub

A few notes:

  1. I wasn’t sure from which Visual Studio version TF.exe was supported. I thought Visual Studio 2005 or 2008, but got confirmed it was Visual Studio 2005 (a.k.a. 8) by Love the elegance of F#. This code looks for the TFS Command line tool and returns Somepath or None.
  2. The Visual Studio names and version numbers are a mess, so I usually first look at the Wikipedia Microsoft Visual Studio History table.
  3. The same holds for many other numbers and registry paths.INFO: Visual Studio version numbers is of great help here.
  4. The base registry path depends if you are running on an x64 or x86 system I used the PROCESSOR_ARCHITECTURE  and PROCESSOR_ARCHITEW6432 environment variables to detect which bitness was running as described in HOWTO: Detect Process Bitness – David Wang – MSDN Blogs (I blogged about that before: Windows batch file to set ProgramFilesX86 directory for 32-bit program files on x86 and x64 systems via: Stack Overflow).
  5. Since I have no VM that has all these Visual Studio installations installed, reg query usually gives an error message. The 2^>NUL trick gets around that: Windows Batch: reg query key value to a variable but do not display error if key doesn’t exist – Stack Overflow.


via: Find an installed tf.exe, then run it with the command-line parameters specified.. PS:

This post supercedes using tf to list the workspaces for the current directory in Team Foundation System « The Wiert Corner – irregular stream of stuff.

One Response to “Find an installed tf.exe, then run it with the command-line parameters specified.”

  1. […] above tf-show-changeset-details-on-console.bat batch file uses tf.bat that hunts for the location of […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: