Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Create Shortcut Using Command Line

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
CCD-DSS
Asked:
CCD-DSS
  • 2
2 Solutions
 
ParanormasticCryptographic EngineerCommented:
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
 
si_shamilCommented:
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
 
si_shamilCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now