Solved

Create Shortcut Using Command Line

Posted on 2008-10-07
5
173 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

12 Experts available now in Live!

Get 1:1 Help Now