Create Desktop Icon

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search

This is a silent installer for desktop shortcuts, it uses a Jscript to create the shortcuts.

WPKG Packages

The following are some example desktop shortcuts for Windows 32 and 64-bit.

WPKG_ROOT is the folder where WPKG Server is installed into, I set it from WPKG Client.

<?xml version="1.0" encoding="UTF-8"?>

<packages>
    <package
        id="RTM592shortcutHelp"
        name="Lemoine RTM Shortcut Help"
        revision="1"
        priority="10"
        reboot="false">
        
        <!-- create a folder shortcut with a different icon -->
        
         <check type="file" condition="exists" path="%ALLUSERSPROFILE%\Desktop\RTM v5.92 Hilfe.lnk" />
        
        <install cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == x86 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles%\RTM592\help" /name:"RTM v5.92 Hilfe" /icon:"%SystemRoot%\system32\shell32.dll, 23"' />
        <install cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == AMD64 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles(x86)%\RTM592\help" /name:"RTM v5.92 Hilfe" /icon:"%SystemRoot%\system32\shell32.dll, 23"' />

        <upgrade cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == x86 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles%\RTM592\help" /name:"RTM v5.92 Hilfe" /icon:"%SystemRoot%\system32\shell32.dll, 23"' />
        <upgrade cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == AMD64 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles(x86)%\RTM592\help" /name:"RTM v5.92 Hilfe" /icon:"%SystemRoot%\system32\shell32.dll, 23"' />



        <remove cmd='%ComSpec% /c if exist "%ALLUSERSPROFILE%\Desktop\RTM v5.92 Hilfe.lnk" del /f /q "%ALLUSERSPROFILE%\Desktop\RTM v5.92 Hilfe.lnk"' />
    </package>

    <package
        id="RTM592shortcutEngineering"
        name="Lemoine RTM Shortcut Engineering License"
        revision="1"
        priority="10"
        reboot="false">
        
        <!-- create a shortcut with arguments for the executable -->
        
         <check type="file" condition="exists" path="%ALLUSERSPROFILE%\Desktop\RTM v5.92 Toolbar Engineering.lnk" />

        <install cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == x86 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles%\RTM592\RtmBar.exe" /name:"RTM v5.92 Toolbar Engineering" /args:"/K9A00946004"' />
        <install cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == AMD64 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles(x86)%\RTM592\RtmBar.exe" /name:"RTM v5.92 Toolbar Engineering" /args:"/K9A00946004"' />

        <upgrade cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == x86 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles%\RTM592\RtmBar.exe" /name:"RTM v5.92 Toolbar Engineering" /args:"/K9A00946004"' />
        <upgrade cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == AMD64 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles(x86)%\RTM592\RtmBar.exe" /name:"RTM v5.92 Toolbar Engineering" /args:"/K9A00946004"' />

        <remove cmd='%ComSpec% /c if exist "%ALLUSERSPROFILE%\Desktop\RTM v5.92 Toolbar Engineering.lnk" del /f /q "%ALLUSERSPROFILE%\Desktop\RTM v5.92 Toolbar Engineering.lnk"' />
    </package>

    <package
        id="RTM592shortcutLocal"
        name="Lemoine RTM Shortcut Local License"
        revision="1"
        priority="10"
        reboot="false">
        
        <!-- create a regular shortcut for an executable -->
        
         <check type="file" condition="exists" path="%ALLUSERSPROFILE%\Desktop\RTM v5.92 Toolbar.lnk" />
        
        <install cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == x86 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles%\RTM592\RtmBar.exe" /name:"RTM v5.92 Toolbar"' />
        <install cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == AMD64 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles(x86)%\RTM592\RtmBar.exe" /name:"RTM v5.92 Toolbar"' />
        
        <upgrade cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == x86 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles%\RTM592\RtmBar.exe" /name:"RTM v5.92 Toolbar"' />
        <upgrade cmd='%ComSpec% /c if %PROCESSOR_ARCHITECTURE% == AMD64 cscript.exe "%WPKG_ROOT%\tools\CreateShortCut.js" /target:"%ProgramFiles(x86)%\RTM592\RtmBar.exe" /name:"RTM v5.92 Toolbar"' />
        
        <remove cmd='%ComSpec% /c if exist "%ALLUSERSPROFILE%\Desktop\RTM v5.92 Toolbar.lnk" del /f /q "%ALLUSERSPROFILE%\Desktop\RTM v5.92 Toolbar.lnk"' />
    </package>
</packages>

JavaScript helper

This is the Jscript to create the shortcuts, place it in the tools folder of your WPKG server installation and name it CreateShortCut.js

/*
Script to create a desktop shortcut
 
Usage:
    CreateShortCut.js {options}
 
    Options:
        /name:"name of the shortcut to create" ... required
        /target:"fully qualified path to the target file or folder" ... required
        /workdir:"fully qualified path to the working folder of the file" ... optional
        /args:"any command line arguments for the file" ... optional
        /icon:"fully qualified path to the icon resource" ... optional
            OR /icon:"fully qualified path to the icon resource, zero-based icon index"
        /descr:"description of the shortcut" ... optional
        /saveto:"saveto path specifies where shortcut is to be saved" ... optional, default: AllUsersDestop
*/
 
var argsNamed = WScript.Arguments.Named;
var argsUnnamed = WScript.Arguments.Unnamed;
 
var WshShell = WScript.CreateObject("WScript.Shell");
var FSobj = WScript.CreateObject("Scripting.FileSystemObject");
var strDesktop = WshShell.SpecialFolders("AllUsersDesktop");
 
var LinkName = null;
var LinkTarget = null;
var LinkWorkDir = null;
var LinkArgs = null;
var LinkIcon = null;
var LinkDescr = null;
var LinkSaveto = null;
 
if ( argsNamed.Exists("name") ) {
    LinkName = argsNamed.Item("name");
 
    if ( LinkName == null ) {
        WScript.StdErr.WriteLine("Name missing /name:\"{name}\" - exiting ...");
        WScript.Quit(4);
    }
} else {
    WScript.StdErr.WriteLine("Option /name:\"{name}\" missing - exiting ...");
    WScript.Quit(3);
}
 
if ( argsNamed.Exists("target") ) {
    LinkTarget = argsNamed.Item("target");
 
    if ( LinkTarget == null ) {
        WScript.StdErr.WriteLine("Target path missing /target:\"{target path}\" - exiting ...");
        WScript.Quit(2);
    }
} else {
    WScript.StdErr.WriteLine("Option /target:\"{target path}\" missing - exiting ...");
    WScript.Quit(1);
}
 
if ( argsNamed.Exists("workdir") ) {
    LinkWorkDir = argsNamed.Item("workdir");
 
    if ( LinkWorkDir == null ) {
        WScript.StdErr.WriteLine("Working directory path missing /workdir:\"{folder path}\" - exiting ...");
        WScript.Quit(5);
    }
} else {
    /* set the folder containing the file as default
    do not set this for target folders */
    if ( FSobj.FileExists(LinkTarget) ) LinkWorkDir = FSobj.GetParentFolderName(LinkTarget);
}
 
if ( argsNamed.Exists("args") ) {
    LinkArgs = argsNamed.Item("args");
 
    if ( LinkArgs == null ) {
        WScript.StdErr.WriteLine("Arguments missing /args:\"{arguments}\" - exiting ...");
        WScript.Quit(6);
    }
}
 
if ( argsNamed.Exists("icon") ) {
    LinkIcon = argsNamed.Item("icon");
 
    if ( LinkIcon == null ) {
        WScript.StdErr.WriteLine("Icon location missing /icon:\"{full path to icon resource}[, {index}]\" - exiting ...");
        WScript.Quit(7);
    }
}
 
if ( argsNamed.Exists("descr") ) {
    LinkDescr = argsNamed.Item("descr");
 
    if ( LinkDescr == null ) {
        WScript.StdErr.WriteLine("Description missing /descr:\"{description}\" - exiting ...");
        WScript.Quit(8);
    }
}

if ( argsNamed.Exists("saveto") ) {
    LinkSaveto = argsNamed.Item("saveto");
 
    if ( LinkSaveto == null ) {
        WScript.StdErr.WriteLine("Saveto path missing /saveto:\"{saveto}\" - exiting ...");
        WScript.Quit(9);
    }
} else {
	LinkSaveto = strDesktop
}

var oShellLink = WshShell.CreateShortcut(FSobj.BuildPath(LinkSaveto, LinkName + ".lnk"));
 
oShellLink.TargetPath = LinkTarget;
if ( LinkWorkDir != null ) oShellLink.WorkingDirectory = LinkWorkDir;
if ( LinkArgs != null ) oShellLink.Arguments = LinkArgs;
if ( LinkIcon != null ) oShellLink.IconLocation = LinkIcon;
if ( LinkDescr != null ) oShellLink.Description = LinkDescr;
 
oShellLink.Save();
 
WScript.Quit(0);