Create Shortcuts for the Current User defined by the Current User Input (VBS)

Purpose: Create a shortcut in the current user desktop and current user Start Menu, defined by user

In corporate environments, standard users rarely have permissions to edit shortcuts for a workstation for all the users. You might come up with a scenario where you need to give users permission to create shortcuts for an application. Most importantly, the shortcut actually needs parameters to work correctly. To reduce the amount of Help Desk calls, you can create a script that creates the shortcuts correctly for the current users by asking the parameter. The parameter can be a server, http-address, profile name, application environment, and so on. This script is extremely helpful in a situation where the System Administrator might not know what parameter each user is actually using or creating all the different scenarios for users might not be cost-efficient. This of course requires that the users know which environment they are using, or this will not work as intended.

Usage: cscript.exe IT_APP_VBS_CreateShortcutsFromUserInput (User Input Required)

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
64
' *********************************************************************************
' ** Script Name: IT_APP_VBS_CreateShortcutsFromUserInput
' ** Created on: 8.8.2012
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: Create a shortcut in the current user desktop and current user Start Menu, defined by user
' ** Usage: IT_APP_VBS_CreateShortcutsFromUserInput (User Inserted Value)
' **
' ** 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 / 8.8.2012 / Initial version.
' ** 1.1 / Jyri Lehtonen / 31.3.2013 / Created better configuration options.
' *********************************************************************************
Option Explicit
 
Dim newfolder, WshShell, objNetwork, oMyShortcut
Dim PopupTitle, PopupMessage, SuccessText, userInput
Dim strShortcutName, strStartmenuName, strShortcutWorkingDir, strShortcutTargetPath
Dim bolEnableCustomIcon, strShortcutIconLocation, strDesktopLocation, strStartMenuLocation
 
Set objNetwork = CreateObject("Wscript.Network")
' *********************************************************************************
' ** 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"
strDesktopLocation = "c:\Users\" & objNetwork.UserName & "\desktop\"
strStartMenuLocation = "C:\Users\" & objNetwork.UserName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\"
' *********************************************************************************
 
PopupMessage = "Insert a value. The value will be added into the shortcut parameters"           
PopupTitle = "User Defined Value"
userInput = InputBox(PopupMessage, PopupTitle)
 
If userInput = "" Then    
    MsgBox "Action has been Cancelled.",16
 
Else 
    set WshShell = CreateObject("WScript.Shell")
    set oMyShortcut = WshShell.CreateShortcut(strDesktopLocation + strShortcutName)
    oMyShortcut.TargetPath = strShortcutTargetPath
    oMyShortcut.Arguments = userInput
    oMyShortcut.WorkingDirectory = strShortcutWorkingDir
    if bolEnableCustomIcon = true Then
        oMyShortcut.IconLocation = strShortcutIconLocation
    End if
    oMyShortCut.Save
 
    SuccessText = "You have created your shortcuts with the following parameters: " & userInput & ". You can now start the application from the shortcut."
    MsgBox SuccessText, 64
End If
' *********************************************************************************
' ** Script Name: IT_APP_VBS_CreateShortcutsFromUserInput
' ** Created on: 8.8.2012
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: Create a shortcut in the current user desktop and current user Start Menu, defined by user
' ** Usage: IT_APP_VBS_CreateShortcutsFromUserInput (User Inserted Value)
' **
' ** 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 / 8.8.2012 / Initial version.
' ** 1.1 / Jyri Lehtonen / 31.3.2013 / Created better configuration options.
' *********************************************************************************
Option Explicit

Dim newfolder, WshShell, objNetwork, oMyShortcut
Dim PopupTitle, PopupMessage, SuccessText, userInput
Dim strShortcutName, strStartmenuName, strShortcutWorkingDir, strShortcutTargetPath
Dim bolEnableCustomIcon, strShortcutIconLocation, strDesktopLocation, strStartMenuLocation

Set objNetwork = CreateObject("Wscript.Network")
' *********************************************************************************
' ** 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"
strDesktopLocation = "c:\Users\" & objNetwork.UserName & "\desktop\"
strStartMenuLocation = "C:\Users\" & objNetwork.UserName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\"
' *********************************************************************************

PopupMessage = "Insert a value. The value will be added into the shortcut parameters"           
PopupTitle = "User Defined Value"
userInput = InputBox(PopupMessage, PopupTitle)

If userInput = "" Then    
	MsgBox "Action has been Cancelled.",16

Else 
	set WshShell = CreateObject("WScript.Shell")
	set oMyShortcut = WshShell.CreateShortcut(strDesktopLocation + strShortcutName)
	oMyShortcut.TargetPath = strShortcutTargetPath
	oMyShortcut.Arguments = userInput
	oMyShortcut.WorkingDirectory = strShortcutWorkingDir
	if bolEnableCustomIcon = true Then
		oMyShortcut.IconLocation = strShortcutIconLocation
	End if
	oMyShortCut.Save

	SuccessText = "You have created your shortcuts with the following parameters: " & userInput & ". You can now start the application from the shortcut."
	MsgBox SuccessText, 64
End If

 

Leave a Reply

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


nine + = eighteen

Post Navigation