是否可以使用 PHP 创建 Windows 快捷方式? [英] Is it possible to create a Windows shortcut using PHP?
问题描述
我正在编写一个脚本来整理散布在我的硬盘驱动器上的一堆媒体,到目前为止它在家里(在我的 Mac 上)运行良好,因为我在目录中使用符号链接给人的印象是一切都是组织在一个位置,而实际数据分布在 4 个驱动器中.
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.
不幸的是,我必须在工作中使用 Windows,当然在 PHP 5.3 之前没有符号链接支持(我假设这需要 Vista,因为那时命令行工具mklink"首次出现).
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?
推荐答案
感谢上面的回答,我发现你确实可以从 php 调用 COM,这是我的 symlink() 替换的初稿:
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();
}
}
这篇关于是否可以使用 PHP 创建 Windows 快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!