How to Keep Your Win32 PATH Super Short

| | Comments (0) | TrackBacks (0)
In two words, .cmd wrappers.

I keep my win32 PATH environment variable short. Really short. Like, there are some default windows folders that have to be there, I keep it to that plus one more directory. Theoretically, you could just put the wrappers in one of the system directories and have  the shortest path ever. The output of the PATH command should never be longer than:
PATH=F:\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
Why? I like to think it's because I was burned at work one-too-many times by my PATH being so long it broke the build. There's a limit on how long it can be, I think it's some max string length of windows (248 characters? I can't even remember now). Now I think it's because I'm an anal control freak about my puter and how it works.

Write one little batch file for each .exe and batch you ever need to run. And you put every batch file in one directory, and you add that to your PATH. You laugh at me now, but look who has the shortest PATH ever! You too can have a super-short PATH, and here's how.

  1. Get a new sexy Western Digital raptor hard drive, or create a partition or file share for your wrappers. Shortest PATH is win32 defaults plus a 3-letter drive like 'F:\'.
    • You can also install everything here, nice!
  2. Note down your current PATH, because for sure we're going to break something for a little while.
  3. Add your new drive directory to your PATH, and remove any other directories that look like software put them there. Keep anything that looks like 'C:\Windows'
  4. Write a small batch file for each .exe you actually use. Do this one-at-a-time, or else you'll never catch typos.
    • Use 'start' for gui programs so you can spawn them without the pesky cmd shell hanging around.
    • Use 'setlocal' and 'set PATH=F:\application\installed\here;%PATH%' liberally.
    • Use '%0' and its expanded friends '%~dp0' so you can copy and paste your wrapper to do the next one.
For example, say you want to wrap Roxio. Roxio comes with my sexy Plextor SATA drive. Roxio can be considered a significant polluter of the environment. It installs shared dlls by default in a 42-character long PATH entry, 'c:\Program Files\Common Files\Roxio Shared\'. Only the apps in the output of 'dir /s /b "c:\Program Files\Roxio\*.exe"' ever use this directory.
  1. Make 'F:\creator7.cmd'
  2. Edit it to prepend the common directory to its setlocal'd PATH.
  3. Edit it to prepend 'c:\Program Files\Roxio\Easy Media Creator 7\Creator Classic\' to its setlocal'd PATH.
  4. Edit it to start %~n0.
  5. Copy it to 'F:\backupnow.cmd' once it works right.
I know it breaks the example and that I should use my F:\Roxio.cmd, but here is my F:\gvim.cmd
:setup
@echo off
setlocal
PATH=%~dp0vim\vim64;%PATH%
start %~n0.exe %*
exit /b %ERRORLEVEL%
Hopefully you get (and never have to use) the idea. Sometimes, I really do miss my Mac.

0 TrackBacks

Listed below are links to blogs that reference this entry: How to Keep Your Win32 PATH Super Short.

TrackBack URL for this entry: http://skull.piratehaven.org/~epu/mt/mt-tb.cgi/57

Leave a comment

Recent Tweets