Solved

Create Shortcut Using Command Line

Posted on 2008-10-07
5
171 Views
Last Modified: 2014-11-20
I am trying to create a shortcut in the start menu using command line scripting so i can add it to group policy to be added to several machines.
0
Comment
Question by:CCD-DSS
  • 2
5 Comments
 
LVL 31

Accepted Solution

by:
Paranormastic earned 250 total points
ID: 22662192
You could also just create the shortcut once, put it onto a shared folder, and have GPO or a logon script copy it over.  Personally I think it is just easiest to just right-click - create shortcut and move it, but if you need to do it programmatically:
http://www.thescarms.com/vbasic/wshom.aspx
http://www.ss64.com/nt/shortcut.html
0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22665340
Here is a simple shortcut creation function in VBScript

'==================================================================================
 

' Function Name : CreateShortcut(pShortcutPath, pTargetPath)
 

' Return value  : True if shortcut created successfuly, False if not
 

' Author        : Alex Simenduev, www.planetit.ws
 

' Date          : 21/04/2008
 

' Description   : Very basic creation of Shortcut, without extra stuff like
 

'                 Icon, Working directory, Hotkeys, Arguments...
 

'==================================================================================
 

Function CreateShortcut(pShortcutPath, pTargetPath) : CreateShortcut = False : On Error Resume Next
 

	Dim objShell	: Set objShell = WScript.CreateObject("WScript.Shell")
 

	Dim objShortcut	: Set objShortcut = objShell.CreateShortcut(pShortcutPath)
 

	
 

	If Err.Number <> 0 Then
 

		Wscript.Echo "Error " & Err.Number & ": " & Err.Description
 

		Err.Clear
 

	Else
 

		objShortcut.Description = "Shortcut to " & pTargetPath
 

		objShortcut.TargetPath = pTargetPath
 

		objShortcut.Save
 

		
 

		If Err.Number = 0 Then CreateShortcut = True		
 

	End If
 
 
 

	Set objShortcut = Nothing
 

	Set objShell = Nothing
 

End Function

Open in new window

0
 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 250 total points
ID: 22665352
Sorry, snippet pasted wrong

use this:
'==================================================================================

' Function Name : CreateShortcut(pShortcutPath, pTargetPath)

' Return value  : True if shortcut created successfuly, False if not

' Author        : Alex Simenduev, www.planetit.ws

' Date          : 21/04/2008

' Description   : Very basic creation of Shortcut, without extra stuff like

'                 Icon, Working directory, Hotkeys, Arguments...

'==================================================================================
 

Function CreateShortcut(pShortcutPath, pTargetPath) : CreateShortcut = False : On Error Resume Next

	Dim objShell	: Set objShell = WScript.CreateObject("WScript.Shell")

	Dim objShortcut	: Set objShortcut = objShell.CreateShortcut(pShortcutPath)
 

	If Err.Number <> 0 Then

		LogEchoLine "Error " & Err.Number & ": " & Err.Description

		Err.Clear

	Else

		objShortcut.Description = "Shortcut to " & pTargetPath

		objShortcut.TargetPath = pTargetPath

		objShortcut.Save
 

		If Err.Number = 0 Then CreateShortcut = True		
 

	End If
 

	Set objShortcut = Nothing

	Set objShell = Nothing

End Function

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now