4

I'm trying to automate uninstallation of some applications, one of which is XtremeTuner. XtremeTuner saves a command used to uninstall it in the registry under HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\XtremeTuner key. The key has the following value on my machine:

C:\PROGRA~2\XTREME~1\XTREME~1\UNWISE.EXE C:\PROGRA~2\XTREME~1\XTREME~1\INSTALL.LOG

At first I thought that is incorrect, but the path actually works. It turns out a tilde character followed by a number performs something like a tab expansion. A bit error-prone, but ok. So for example:

  • C:\Program~1 resolves to C:\Program Files
  • C:\Program~2 resolves to C:\Program Files (x86)
  • C:\Program~3 resolves to C:\ProgramData

Powershell seems to be aware of it, but not all software does (for example Chocolatey validates the path and concludes it is incorrect).

My questions:

  1. How is this mechanism called? I'm calling it "tilde-completion" for now, but there's probably another name for it.
  2. How do I resolve this tilde-completed path to a normal one?

1 Answer 1

4

How is this mechanism called?

Those are the "8.3 names" generated for compatibility with 16-bit MS-DOS and Windows 3.x software, in which file names were limited to exactly this size.

(File access APIs in those operating systems have this fixed length assumption built into them, so old programs written for Win16 or DOS are permanently affected by the limit even if you run them on later Windows version. Therefore, Windows provides short aliases for long names so that people could still run their old programs on their brand new Windows 95 machines.)

It could be that you're seeing this path because older versions of WISE Installation System actually generated 32-bit installers with a 16-bit launcher (meant to display a friendly error message on Windows 3.x, instead of a generic "invalid .exe file").

It turns out a tilde character followed by a number performs something like a tab expansion. A bit error-prone, but ok.

No, the tilde is not actually expanded at all. Instead, the same file or folder literally has both names assigned to it, and the tilde just happens to be an actual part of 8.3 names that Windows generates. (Some operating systems that deal with FAT-formatted disks are known to generate 8.3 names without a tilde.)

So the expansion is done not by userspace but by the filesystem itself – the FAT or NTFS driver recognizes the same folder as being simultaneously named Program Files and PROGRA~1. There is no guessing involved – the 8.3 name is assigned statically, whenever the item is created or renamed (you can see current 8.3 names using dir /x in Command Prompt), and PROGRA~3 will always remain PROGRA~3 even if PROGRA~2 is deleted.

This also means that anywhere a file path is used, both the full name and the short 8.3 name should be accepted the same, despite the latter being hidden from directory listings. Programs which don't accept an 8.3 name are usually doing something wrong.

(Do note that generation of 8.3 names on NTFS disks can be disabled, so the dir /x command might show some names missing. Disabling 8.3 generation does not invalidate previously assigned names, however.)

How do I resolve this tilde-completed path to a normal one?

Through the Win32 API, you can call GetLongPathName() or GetFullPathName().

Through PowerShell, you can access (Get-Item).FullName or (Get-ChildItem).FullName:

PS C:\Users\Foo> (get-item -force "c:\users\foo\virtua~1").Name
.VirtualBox

PS C:\Users\Foo> (get-item -force "c:\users\foo\virtua~1").FullName
C:\Users\Foo\.VirtualBox

PS C:\Users\Foo> get-item -force docume~1,micros~1,virtua~1 | ft Name,FullName

Name                 FullName
----                 --------
Documents            C:\Users\Foo\Documents
MicrosoftEdgeBackups C:\Users\Foo\MicrosoftEdgeBackups
.VirtualBox          C:\Users\Foo\.VirtualBox
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .