Difference between revisions of "Create Desktop Icon"
From WPKG | Open Source Software Deployment and Distribution
m (Desktop Icon moved to Create Desktop Icon: Better recognition what the content is.) |
(Added saveto parameter for saving shortcut in other than the default directory) |
||
Line 27: | Line 27: | ||
<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% == 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"' /> | <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"' /> | <remove cmd='%ComSpec% /c if exist "%ALLUSERSPROFILE%\Desktop\RTM v5.92 Hilfe.lnk" del /f /q "%ALLUSERSPROFILE%\Desktop\RTM v5.92 Hilfe.lnk"' /> | ||
Line 78: | Line 80: | ||
/* | /* | ||
Script to create a desktop shortcut | Script to create a desktop shortcut | ||
− | + | ||
Usage: | Usage: | ||
CreateShortCut.js {options} | CreateShortCut.js {options} | ||
− | + | ||
Options: | Options: | ||
/name:"name of the shortcut to create" ... required | /name:"name of the shortcut to create" ... required | ||
Line 90: | Line 92: | ||
OR /icon:"fully qualified path to the icon resource, zero-based icon index" | OR /icon:"fully qualified path to the icon resource, zero-based icon index" | ||
/descr:"description of the shortcut" ... optional | /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 argsNamed = WScript.Arguments.Named; | ||
var argsUnnamed = WScript.Arguments.Unnamed; | var argsUnnamed = WScript.Arguments.Unnamed; | ||
− | + | ||
var WshShell = WScript.CreateObject("WScript.Shell"); | var WshShell = WScript.CreateObject("WScript.Shell"); | ||
var FSobj = WScript.CreateObject("Scripting.FileSystemObject"); | var FSobj = WScript.CreateObject("Scripting.FileSystemObject"); | ||
var strDesktop = WshShell.SpecialFolders("AllUsersDesktop"); | var strDesktop = WshShell.SpecialFolders("AllUsersDesktop"); | ||
− | + | ||
var LinkName = null; | var LinkName = null; | ||
var LinkTarget = null; | var LinkTarget = null; | ||
Line 105: | Line 108: | ||
var LinkIcon = null; | var LinkIcon = null; | ||
var LinkDescr = null; | var LinkDescr = null; | ||
− | + | var LinkSaveto = null; | |
+ | |||
if ( argsNamed.Exists("name") ) { | if ( argsNamed.Exists("name") ) { | ||
LinkName = argsNamed.Item("name"); | LinkName = argsNamed.Item("name"); | ||
− | + | ||
if ( LinkName == null ) { | if ( LinkName == null ) { | ||
WScript.StdErr.WriteLine("Name missing /name:\"{name}\" - exiting ..."); | WScript.StdErr.WriteLine("Name missing /name:\"{name}\" - exiting ..."); | ||
Line 117: | Line 121: | ||
WScript.Quit(3); | WScript.Quit(3); | ||
} | } | ||
− | + | ||
if ( argsNamed.Exists("target") ) { | if ( argsNamed.Exists("target") ) { | ||
LinkTarget = argsNamed.Item("target"); | LinkTarget = argsNamed.Item("target"); | ||
− | + | ||
if ( LinkTarget == null ) { | if ( LinkTarget == null ) { | ||
WScript.StdErr.WriteLine("Target path missing /target:\"{target path}\" - exiting ..."); | WScript.StdErr.WriteLine("Target path missing /target:\"{target path}\" - exiting ..."); | ||
Line 129: | Line 133: | ||
WScript.Quit(1); | WScript.Quit(1); | ||
} | } | ||
− | + | ||
if ( argsNamed.Exists("workdir") ) { | if ( argsNamed.Exists("workdir") ) { | ||
LinkWorkDir = argsNamed.Item("workdir"); | LinkWorkDir = argsNamed.Item("workdir"); | ||
− | + | ||
if ( LinkWorkDir == null ) { | if ( LinkWorkDir == null ) { | ||
WScript.StdErr.WriteLine("Working directory path missing /workdir:\"{folder path}\" - exiting ..."); | WScript.StdErr.WriteLine("Working directory path missing /workdir:\"{folder path}\" - exiting ..."); | ||
Line 142: | Line 146: | ||
if ( FSobj.FileExists(LinkTarget) ) LinkWorkDir = FSobj.GetParentFolderName(LinkTarget); | if ( FSobj.FileExists(LinkTarget) ) LinkWorkDir = FSobj.GetParentFolderName(LinkTarget); | ||
} | } | ||
− | + | ||
if ( argsNamed.Exists("args") ) { | if ( argsNamed.Exists("args") ) { | ||
LinkArgs = argsNamed.Item("args"); | LinkArgs = argsNamed.Item("args"); | ||
− | + | ||
if ( LinkArgs == null ) { | if ( LinkArgs == null ) { | ||
WScript.StdErr.WriteLine("Arguments missing /args:\"{arguments}\" - exiting ..."); | WScript.StdErr.WriteLine("Arguments missing /args:\"{arguments}\" - exiting ..."); | ||
Line 151: | Line 155: | ||
} | } | ||
} | } | ||
− | + | ||
if ( argsNamed.Exists("icon") ) { | if ( argsNamed.Exists("icon") ) { | ||
LinkIcon = argsNamed.Item("icon"); | LinkIcon = argsNamed.Item("icon"); | ||
− | + | ||
if ( LinkIcon == null ) { | if ( LinkIcon == null ) { | ||
WScript.StdErr.WriteLine("Icon location missing /icon:\"{full path to icon resource}[, {index}]\" - exiting ..."); | WScript.StdErr.WriteLine("Icon location missing /icon:\"{full path to icon resource}[, {index}]\" - exiting ..."); | ||
Line 160: | Line 164: | ||
} | } | ||
} | } | ||
− | + | ||
if ( argsNamed.Exists("descr") ) { | if ( argsNamed.Exists("descr") ) { | ||
LinkDescr = argsNamed.Item("descr"); | LinkDescr = argsNamed.Item("descr"); | ||
− | + | ||
if ( LinkDescr == null ) { | if ( LinkDescr == null ) { | ||
WScript.StdErr.WriteLine("Description missing /descr:\"{description}\" - exiting ..."); | WScript.StdErr.WriteLine("Description missing /descr:\"{description}\" - exiting ..."); | ||
Line 170: | Line 174: | ||
} | } | ||
− | + | 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; | oShellLink.TargetPath = LinkTarget; | ||
if ( LinkWorkDir != null ) oShellLink.WorkingDirectory = LinkWorkDir; | if ( LinkWorkDir != null ) oShellLink.WorkingDirectory = LinkWorkDir; | ||
Line 177: | Line 192: | ||
if ( LinkIcon != null ) oShellLink.IconLocation = LinkIcon; | if ( LinkIcon != null ) oShellLink.IconLocation = LinkIcon; | ||
if ( LinkDescr != null ) oShellLink.Description = LinkDescr; | if ( LinkDescr != null ) oShellLink.Description = LinkDescr; | ||
− | + | ||
oShellLink.Save(); | oShellLink.Save(); | ||
− | + | ||
WScript.Quit(0); | WScript.Quit(0); | ||
</source> | </source> |
Latest revision as of 16:08, 24 April 2014
Contents
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);