Create a Shortcut for All Users of a workstation (VBS)

Purpose: Create a Windows Shortcut in the Public Desktop and Public Start Menu.

Are you in need to create shortcuts for all the users of a workstation? Do you have some silly vendor provided application that just needs to have its shortcuts fixed? And most importantly – you need to do this OFTEN? Then scripting a shortcut template is the answer for you. With this code example, you can create your own shortcuts. You might not have the time to do it yourself, so you can use one I have created. Important fact is that by using this method the actual target does not need to exist by the time of the creation – the shortcuts are created anyway!

Usage: cscript.exe CreateShortcuts.vbs (no parameters exist)

Configuration: You need to change the configuration in “Configure the script” -part of the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
' *********************************************************************************
' ** Script Name: IT_APP_VBS_CreateShortcuts
' ** Created on: 21.6.2012
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: Create a shortcut in the Public Desktop and Public Start Menu.
' ** Usage: IT_APP_VBS_CreateShortcuts (no parameters exist)
' **
' ** License: This program is free software: you can redistribute it and/or modify
' ** it under the terms of the GNU General Public License as published by
' ** the Free Software Foundation, either version 3 of the License, or
' ** (at your option) any later version.
' **
' ** This program is distributed in the hope that it will be useful,
' ** but WITHOUT ANY WARRANTY; without even the implied warranty of
' ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' ** GNU General Public License for more details.
' ** 
' ** History: 
' ** 1.0 / Jyri Lehtonen / 21.6.2012 / Initial version.
' ** 1.1 / Jyri Lehtonen / 29.3.2013 / Created better configuration options.
' *********************************************************************************
' *********************************************************************************
' ** Configure the script:
' *********************************************************************************
strShortcutName = "Application Shortcut.lnk"
strStartmenuName = "Application Startmenu Folder Name"
strShortcutWorkingDir = "C:\EXAMPLE\"
strShortcutTargetPath = "C:\EXAMPLE\Executable.exe"
bolEnableCustomIcon = false
strShortcutIconLocation = "C:\EXAMPLE\ExecutablesIcon.ico"
strShortcutArguments = " "
strDesktopLocation = "c:\Users\Public\desktop\"
strStartMenuLocation = "c:\ProgramData\Microsoft\Windows\Start Menu\Programs\"
' *********************************************************************************
 
'Create a shortcut in Public Desktop
set WshShell = CreateObject("WScript.Shell")
set oMyShortcut = WshShell.CreateShortcut(strDesktopLocation + strShortcutName)
oMyShortcut.TargetPath = strShortcutTargetPath
oMyShortcut.Arguments = strShortcutArguments
oMyShortcut.WorkingDirectory = strShortcutWorkingDir
if bolEnableCustomIcon = true Then
    oMyShortcut.IconLocation = strShortcutIconLocation
End if
oMyShortCut.Save
 
'Create a folder in the Start Menu (if it does not exist)
set filesys=CreateObject("Scripting.FileSystemObject")
If  Not filesys.FolderExists(strStartMenuLocation + strStartmenuName) Then
   newfolder = filesys.CreateFolder (strStartMenuLocation + strStartmenuName)
End If
 
'Create a shortcut in Public Start Menu.
set WshShell = CreateObject("WScript.Shell")
set oMyShortcut = WshShell.CreateShortcut(strStartMenuLocation + strStartmenuName + "\" + strShortcutName)
oMyShortcut.TargetPath = strShortcutTargetPath
oMyShortcut.Arguments = strShortcutArguments
oMyShortcut.WorkingDirectory = strShortcutWorkingDir
if bolEnableCustomIcon = true Then
    oMyShortcut.IconLocation = strShortcutIconLocation
End if
oMyShortCut.Save
' *********************************************************************************
' ** Script Name: IT_APP_VBS_CreateShortcuts
' ** Created on: 21.6.2012
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: Create a shortcut in the Public Desktop and Public Start Menu.
' ** Usage: IT_APP_VBS_CreateShortcuts (no parameters exist)
' **
' ** License: This program is free software: you can redistribute it and/or modify
' ** it under the terms of the GNU General Public License as published by
' ** the Free Software Foundation, either version 3 of the License, or
' ** (at your option) any later version.
' **
' ** This program is distributed in the hope that it will be useful,
' ** but WITHOUT ANY WARRANTY; without even the implied warranty of
' ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' ** GNU General Public License for more details.
' ** 
' ** History: 
' ** 1.0 / Jyri Lehtonen / 21.6.2012 / Initial version.
' ** 1.1 / Jyri Lehtonen / 29.3.2013 / Created better configuration options.
' *********************************************************************************
' *********************************************************************************
' ** Configure the script:
' *********************************************************************************
strShortcutName = "Application Shortcut.lnk"
strStartmenuName = "Application Startmenu Folder Name"
strShortcutWorkingDir = "C:\EXAMPLE\"
strShortcutTargetPath = "C:\EXAMPLE\Executable.exe"
bolEnableCustomIcon = false
strShortcutIconLocation = "C:\EXAMPLE\ExecutablesIcon.ico"
strShortcutArguments = " "
strDesktopLocation = "c:\Users\Public\desktop\"
strStartMenuLocation = "c:\ProgramData\Microsoft\Windows\Start Menu\Programs\"
' *********************************************************************************

'Create a shortcut in Public Desktop
set WshShell = CreateObject("WScript.Shell")
set oMyShortcut = WshShell.CreateShortcut(strDesktopLocation + strShortcutName)
oMyShortcut.TargetPath = strShortcutTargetPath
oMyShortcut.Arguments = strShortcutArguments
oMyShortcut.WorkingDirectory = strShortcutWorkingDir
if bolEnableCustomIcon = true Then
	oMyShortcut.IconLocation = strShortcutIconLocation
End if
oMyShortCut.Save

'Create a folder in the Start Menu (if it does not exist)
set filesys=CreateObject("Scripting.FileSystemObject")
If  Not filesys.FolderExists(strStartMenuLocation + strStartmenuName) Then
   newfolder = filesys.CreateFolder (strStartMenuLocation + strStartmenuName)
End If

'Create a shortcut in Public Start Menu.
set WshShell = CreateObject("WScript.Shell")
set oMyShortcut = WshShell.CreateShortcut(strStartMenuLocation + strStartmenuName + "\" + strShortcutName)
oMyShortcut.TargetPath = strShortcutTargetPath
oMyShortcut.Arguments = strShortcutArguments
oMyShortcut.WorkingDirectory = strShortcutWorkingDir
if bolEnableCustomIcon = true Then
	oMyShortcut.IconLocation = strShortcutIconLocation
End if
oMyShortCut.Save

 

Leave a Reply

Your email address will not be published. Required fields are marked *


two + two =

Post Navigation