Passing Command Line Arguments to a VB6 program on Windows 7/8

faxviewer_sq_header

My long national nightmare is over!

Back in the late 90s, I wrote a fax viewer program for my then employer, now client.  It was written in VB6 and has been running  without incident on their fleet of XP machines for well over a decade.

We started to migrate off XP and the fax viewer worked fine, but our ability to “launch by association” went away.  We could open the fax viewer, navigate to our folder full of faxes, open one up and do our thing; but double-clicking on a fax no longer opened the fax up automatically.

The command line was being passed just fine, but for whatever reason, the app just wouldn’t open the file.

MsgBox’s showed me the command line and it was exactly what we were passing… and so I left it as an “inconvenience” – we could still get to the fax, but not as slickly as just clicking on the link in the email.

I looked everywhere – thinking it had to do with security contexts, that the UAC was getting in the way of blahdy-blahdy-blah, I had no idea what.  I didn’t stay up on the intricacies of how the security models changed between “Run it All, All the Time” under XP to the more restrictive security models of Vista/7/8, so I figured it had to be that, and I chalked it off.

Fast forward a bit over a year, and we’re rolling out Windows 8.1 now to the rest of the desks that hadn’t gotten Windows 7.  The fax viewer works the same way on Windows 8.1 and it still drives me nuts, so I dug back  into the code to look again, put back my MsgBox’s to look at the command line arguments at runtime, and it hit me.

QUOTATION MARKS!

WindowsXP passes the command line as C:\TEMP\MYFILE.FAX and Win7/8 passes it surrounded by quotes “C:\TEMP\MYFILE.FAX” and when I did my FileExists checking using the FileSystemObject, the check failed when it was passed the filename wrapped in quotes, so it never loaded the file.

Once I stripped out the quotes from the command-line argument, then it passed the FileExists check, loaded up the document and all was well.

Only took me 13 months, but, dammit, I figured it out!