Fog Creek Software
Discussion Board

Follow shortcuts in Visual Basic?

OK, another (hopefully) simple Windows question from one used to Unix niceties:

At work we have an IIS server farm, four instances running a Web application. The app writes output files to an Output folder under its Web root - so, four copies of the Output folder.

We have a custom-written VB utility that reads a file in the Output folder, converts it, and writes the results to a subfolder.

I want to redirect all the Output folders in the farm to a central location, so that

1) it's written to a fault-tolerant (RAID) disk instead of the single disk on the Web server,
2) our conversion util only needs to look in one location instead of walking the list of servers and handling errors related to some of them not being up
3) end-users of the app create a single copy of the output file, rather than a copy on whatever server the load balancer assigned them to, to avoid problems with duplicate data and cleaning up the files.

On Unix, I'd replace the Output folder with a symbolic link to a mounted directory, and none of the apps would know the difference.

I tried this on Windows by creating a shortcut to my common location:

symbolic path: \\server1\path\to\output\file.txt

symlink: \\server1\path\to\output -> \\server2\path\to\real\output

physical file: \\bigraidbox\path\to\real\output\file.txt

But this only works in very limited conditions:

I can navigate there thru Explorer. If I go to \\server1, and go down to the output folder and doubnle-click it, I am now on \\bigraidbox in its output folder.

If I put '\\server1\path\to\output' in the Run... dialog in the start menu, I get an Exporer window for the output folder on \\bigraidbox

But if I put '\\server1\path\to\output\file.txt' in the Run..  dialog, or in the File.Open call in VB, we get "Cannot find the file '\\server1\path\to\output\file.txt' ...

Is it possible to use shortcuts on Windows, specifically in VB, the way I would use symlinks on Unix? In particular, is there any way to do something like this without invoking a special API -- to do it in a way that's transparent to the applicatioons? I can (somewhat) control what we write in our custom conversion app that reads the file in Output, but I can't modify the code of the packaged app that *writes* the file to be converted to Output in the first place. So any solution must be transparent to our vendor-supplied app. I've done a fair bit of searching on Google and Google Groups abouit this, and found a couple references to some hairy .lnk-parsing VB classes, but nothing definitive :-(


Wednesday, March 17, 2004

Under NTFS you can create both hard and symbolic links.  Symbolic links (Junction Points in NTFS terminology) can point to directories on other drives.  Applications would not know the difference. 

A "shortcut" is just a file (extension is .lnk) that contains a reference that the shell can follow and is not the same thing.

Do a google search for Junction Point and you'll find more information about it as well as tools to create them.

Almost Anonymous
Wednesday, March 17, 2004

Thanks, that looks promising. I thought about junction points as I was investigating this, and looked up some docs, but they seem to indicate that the target of a junction point is a device locally attached to the same machine. Can the junction point to a share on a separate machine?

Wednesday, March 17, 2004

MS says "Any valid Windows 2000 local path".  That would seem to imply that only local drives/directories can be mounted w/ a junction point.  However, I've read that pretty much any valid path can be the target of the junction point.

My recommendation is just to try it (it's simple enough).

Almost Anonymous
Wednesday, March 17, 2004

Why create the local file at all? When you've got the received file as a binary stream, just send it to a message queue or a web service on the central server, which then processes it and writes it to the central directory...


Wednesday, March 17, 2004

Wednesday, March 17, 2004

It is not possible in VB to create shortcuts because a shortcut is not an ordinary file. It is an object of the shell with properties such as target, current dir, name and so on. Creating a shortcut would require implementation of COM interfaces (IShellLink, IPersist etc.) which is not possible through plain VB.

However, there is a workaround I saw a few years back on some site I forgot. It was not fool-proof though. The guy was trying to be funny, but he wasn't. He either opened the file or something I don't quite remember, then obtained the CSIDL for the Recent Folder. Once the shortcut was there in the Recent folder, he copied it to wherever he wanted.

But I don't think a shortcut is what you're looking for. You're probably looking for a UNC path or mapping a physical path to a virtual path? Is that what you're looking for? It is possible again, but only with the help of API.

Sathyaish Chakravarthy
Thursday, March 18, 2004

"The guy was trying to be funny, but he wasn't."

Those who live in glass houses should not throw stones.

Thursday, March 18, 2004

*  Recent Topics

*  Fog Creek Home