I'm writing a script to tidy up a bunch of media spread across my hard drives, and it works pretty well so far at home (on my Mac) as I use symlinks in a directory to give the impression that everything is organised in one location, whilst the actual data is spread across the 4 drives.
Unfortunately, I have to use Windows at work, and of course there's no symlink support there until PHP 5.3 (and I assume that requires Vista as that's when the command-line tool "mklink" first appeared).
As a workaround, I considered creating a shortcut, but I can't find a way of doing it. Is it possible, or is there a better solution I've not considered?
Thanks to the above answer, I found that you can indeed call COM from php, here's my first draft of a symlink() replacement:
if (! function_exists('symlink')) {
function symlink($target, $link) {
if (! substr($link, -4, '.lnk'))
$link .= '.lnk';
$shell = new COM('WScript.Shell');
$shortcut = $shell->createshortcut($link);
$shortcut->targetpath = $target;
$shortcut->save();
}
}
There is support for junction points (similar to UNIX symlinks) before Vista.
You need the linkd
tool from the windows resource kit (free download).
Shortcuts are just files. You can create shortcut files using the COM WScript API. The sample code does this using Python. If there exists a library for PHP that lets you do COM interop, you should be able to do something similar.
import win32com.client
import winshell
userDesktop = winshell.desktop()
shell = win32com.client.Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(userDesktop + '\\Zimbra Webmail.lnk')
shortcut.Targetpath = r'C:\Program Files\Mozilla Firefox\firefox.exe'
shortcut.Arguments = 'http://mysite.com/auth/preauth.php'
shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox'
shortcut.save()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With