Quantcast
Channel: Encoding – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 160

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

$
0
0

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
01234567890123456789012345678901234567890
          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
012345678901234567890123456789012345678901234567
          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.

–jeroen

via


Filed under: Batch-Files, Development, Encoding, Power User, Scripting, Software Development, Unicode, Windows, Windows 7, Windows 8, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP

Viewing all articles
Browse latest Browse all 160

Trending Articles