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,514 other followers

START: Start a program, **even if it is not on the PATH** ideal to start various versions of apps from DOS

Posted by jpluimers on 2013/01/29

A while ago, I had to adapt a DOS app that used one specific version of Excel to do some batch processing so it would support multiple versions of Excel on multiple versions of Windows.

One of the big drawbacks of DOS applications is that the command lines you can use are even shorter than Windows applications, which depending you how you call an application are:

This is how the DOS app written in Clipper (those were the days, it was even linked with Blinker :) started Excel:

c:\progra~1\micros~2\office11\excel.exe parameters
          1         2         3         4

The above depends on 8.3 short file names that in turn depend on the order in which similar named files and directories have been created.

The trick around this, and around different locations/versions of an application, is to use START to find the right version of Excel.

The reason it works is because in addition to PATH, it checks the App Paths portions in the registry in this order to find an executable:

  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths
    (only Windows 7 and up)
  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
    (all Windows versions)

So when Excel is registered correctly, it will find it.

I fixed the Clipper app to start Excel like this:

C:\WINDOWS\system32\cmd.exe/c start /wait Excel parameters
          1         2         3         4

Actually, for C:\WINDOWS\system32\cmd.exe, I used %ComSpec%, so it is location independent.

Anyway, the prefix grew from 39 to 47 characters, so now there are only 80 characters left for actual parameters (not 88 as we had first). Just enough for the longest parameter list we were sending.

Since starting Excel by itself waited for Excel, I needed the /WAIT parameter for START:

  • /WAIT : Start application and wait for it to terminate

Another thing to note is that there is no space in front of the /C: it will automatically be inserted.



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: