Tuesday, January 4, 2011

Create Windows Shortcut in PHP

This code comes courtesy of Drarok on the stack overflow forums-

However, I've modified the code slightly so you can set a 'working folder'

so you simply call the function like this:
symlink (notepad.exe,newshortcut.lnk,d:\) where the shortcut will be called newshortcut, and the target being notepad.exe and the working directory being D:\

function symlink($target, $link, $workingdir) {
$shell = new COM('WScript.Shell');
$shortcut = $shell->createshortcut($link);
$shortcut->targetpath = $target;
$shortcut->WorkingDirectory = $workingdir;

This also works great in command line EXE files created by bamcompile