Create Desktop Shortcut
Moderators: JRL, Dorian (MJT support)
Create Desktop Shortcut
I am trying to create a desktop shortcut and found a nice script on the forum that does just that; however, it changes the "/" to "\" and I need the forward slash to send along the parameters as in this example from the help file
msched Example Script /filename=testfile.txt /path=c:\outpath\the
VBSTART
Sub NewDesktopShortcut(linkfile,targetpath,windowstyle,hotkey,descr)
Set WshShell = CreateObject("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & linkfile)
oShellLink.TargetPath = targetpath
oShellLink.WindowStyle = windowstyle
oShellLink.Hotkey = hotkey
oShellLink.IconLocation = "C:\consolegrab\ProfileManager\Profile Manager.exe, 0"
oShellLink.Description = descr
oShellLink.WorkingDirectory = strDesktop
oShellLink.Save
End Sub
VBEND
Let>job=Test this variable
let>linkname=%job%.lnk
Let>profile=test
Let>program=C:\consolegrab\ProfileManager\Profile Manager.exe /Profiletouse="%profile%" /Output="Commandline"
VBRun>NewDesktopShortcut,%linkname%,%program%,1,CTRL+SHIFT+R,Profile Manager Shortcut
The line generated from this script in the shortcut looks like this
"C:\consolegrab\ProfileManager\Profile Manager.exe \Profiletouse="test" \Output="Commandline""
Any ideas on how to force it to become a forward slash?
msched Example Script /filename=testfile.txt /path=c:\outpath\the
VBSTART
Sub NewDesktopShortcut(linkfile,targetpath,windowstyle,hotkey,descr)
Set WshShell = CreateObject("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & linkfile)
oShellLink.TargetPath = targetpath
oShellLink.WindowStyle = windowstyle
oShellLink.Hotkey = hotkey
oShellLink.IconLocation = "C:\consolegrab\ProfileManager\Profile Manager.exe, 0"
oShellLink.Description = descr
oShellLink.WorkingDirectory = strDesktop
oShellLink.Save
End Sub
VBEND
Let>job=Test this variable
let>linkname=%job%.lnk
Let>profile=test
Let>program=C:\consolegrab\ProfileManager\Profile Manager.exe /Profiletouse="%profile%" /Output="Commandline"
VBRun>NewDesktopShortcut,%linkname%,%program%,1,CTRL+SHIFT+R,Profile Manager Shortcut
The line generated from this script in the shortcut looks like this
"C:\consolegrab\ProfileManager\Profile Manager.exe \Profiletouse="test" \Output="Commandline""
Any ideas on how to force it to become a forward slash?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
This is because you are passing the arguments as part of the target so it thinks those should be part of the path. You need to use the arguments property of the shortcut object.
This version adds a new parameter for the command line arguments:
This version adds a new parameter for the command line arguments:
Code: Select all
VBSTART
Sub NewDesktopShortcut(linkfile,targetpath,windowstyle,hotkey,descr,parms)
Set WshShell = CreateObject("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & linkfile)
oShellLink.TargetPath = targetpath
oShellLink.Arguments = parms
oShellLink.WindowStyle = windowstyle
oShellLink.Hotkey = hotkey
oShellLink.IconLocation = "C:\consolegrab\ProfileManager\Profile Manager.exe, 0"
oShellLink.Description = descr
oShellLink.WorkingDirectory = strDesktop
oShellLink.Save
End Sub
VBEND
Let>job=Test this variable
let>linkname=%job%.lnk
Let>profile=test
Let>program=C:\consolegrab\ProfileManager\Profile Manager.exe
Let>parms=/Profiletouse="%profile%" /Output="Commandline"
VBRun>NewDesktopShortcut,%linkname%,%program%,1,CTRL+SHIFT+R,Profile Manager Shortcut,parms
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Hi Marcus and kpassaur,
Thanks for this, a very useful script. I made a few mods to pull out more of the variables so I could set them in Macro Script and not have to make any changes to the VBScript. Here's what I'm using:
I do have two questions though...
1) What is the significance of ", 0" in the following line?
Again, thanks again for this great bit of code.
Thanks for this, a very useful script. I made a few mods to pull out more of the variables so I could set them in Macro Script and not have to make any changes to the VBScript. Here's what I'm using:
Code: Select all
VBSTART
Sub NewDesktopShortcut(linkfile,targetpath,parms,windowstyle,hotkey,iconlocation,descr)
Set WshShell = CreateObject("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & linkfile)
oShellLink.TargetPath = targetpath
oShellLink.Arguments = parms
oShellLink.WindowStyle = windowstyle
oShellLink.Hotkey = hotkey
oShellLink.IconLocation = iconlocation
oShellLink.Description = descr
oShellLink.WorkingDirectory = strDesktop
oShellLink.Save
End Sub
VBEND
Let>shortcut_icon_title=My App
Let>linkfile=%shortcut_icon_title%.lnk
Let>profile=my_profile
//Let>targetpath=C:\consolegrab\ProfileManager\Profile Manager.exe
Let>targetpath=C:\Program Files\Dir\myapp.exe
//Let>parms=/Profiletouse="%profile%" /Output="Commandline"
Let>parms=
//1=Normal, 3=Maximized, 7=Minimized
Let>windowstyle=1
//Let>hotkey=CTRL+SHIFT+R
Let>hotkey=
//Note: the icon image is contained within the app exe
//Let>iconlocation=C:\consolegrab\ProfileManager\Profile Manager.exe, 0
Let>iconlocation=C:\Program Files\Dir\myapp.exe, 0
//Let>descr=Profile Manager Shortcut
Let>descr=My App Icon Description
VBRun>NewDesktopShortcut,linkfile,targetpath,parms,windowstyle,hotkey,iconlocation,descr
1) What is the significance of ", 0" in the following line?
- Let>iconlocation=C:\Program Files\Dir\myapp.exe, 0
Again, thanks again for this great bit of code.
Last edited by jpuziano on Tue Jul 10, 2007 8:15 pm, edited 1 time in total.
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
1: 0 means use the first icon resource in the given EXE file. Zero based.
2: 2 does mean run minimized. Perhaps the app in question doesn't like being started minimized.
Documentation on the Shortcut object is here:
http://msdn2.microsoft.com/en-us/library/xk6kst2k.aspx
2: 2 does mean run minimized. Perhaps the app in question doesn't like being started minimized.
Documentation on the Shortcut object is here:
http://msdn2.microsoft.com/en-us/library/xk6kst2k.aspx
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Sounds good, thanks.mtettmar wrote:1: 0 means use the first icon resource in the given EXE file. Zero based.
Your link led me to this link that shows to use 7 for "Minimized":mtettmar wrote:2: 2 does mean run minimized. Perhaps the app in question doesn't like being started minimized.
Documentation on the Shortcut object is here:
http://msdn2.microsoft.com/en-us/library/xk6kst2k.aspx
http://msdn2.microsoft.com/en-us/library/w88k7fw2.aspx
I tried 7 and it worked... now when I right-click the shortcut icon that this script creates and click Properties, it shows "Run: Minimized" which is what I was after.
I will correct the code I posted above to show that 7 is for "Minimized".
Thanks again for this very useful script.
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Hi there,
Great help (all of the above).
If anyone has a minute could you explain how to change the place that the shortcut is placed. Instead of Desktop.
At the moment in my little file moving app I am making the shortcuts (using this VB) and then moving them from the desktop to the desired location.
It works fine but it would be nice to just create the shortcut at the desired location straight away.

Great help (all of the above).
If anyone has a minute could you explain how to change the place that the shortcut is placed. Instead of Desktop.
At the moment in my little file moving app I am making the shortcuts (using this VB) and then moving them from the desktop to the desired location.
It works fine but it would be nice to just create the shortcut at the desired location straight away.

Phil Pendlebury - Linktree
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Just change this line:
strDesktop = WshShell.SpecialFolders("Desktop")
If to your own path you could use:
strDesktop = "c:\mypath\"
But you might also want to do the sensible thing and change the name of the strDesktop variable to something more useful and therefore change all further references of strDesktop in the rest of the code.
If you want to move it to another "special" location change it to, for example:
strStartup = WshShell.SpecialFolders("Startup")
And change references to strDesktop to strStartup.
Take a look at:
http://msdn.microsoft.com/en-us/library ... S.85).aspx
For "special" folders:
http://msdn.microsoft.com/en-us/library ... S.85).aspx
strDesktop = WshShell.SpecialFolders("Desktop")
If to your own path you could use:
strDesktop = "c:\mypath\"
But you might also want to do the sensible thing and change the name of the strDesktop variable to something more useful and therefore change all further references of strDesktop in the rest of the code.
If you want to move it to another "special" location change it to, for example:
strStartup = WshShell.SpecialFolders("Startup")
And change references to strDesktop to strStartup.
Take a look at:
http://msdn.microsoft.com/en-us/library ... S.85).aspx
For "special" folders:
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Hi Marcus,
That was quick thanks.
The location would need to be able to be set by a variable so I think I can do it with what you have done there. I'll try it out shortly.
I'm afraid VB Script is gobbledygook to me so I have to work quite hard to decipher it.
Thank you very much.

That was quick thanks.
The location would need to be able to be set by a variable so I think I can do it with what you have done there. I'll try it out shortly.
I'm afraid VB Script is gobbledygook to me so I have to work quite hard to decipher it.
Thank you very much.

Phil Pendlebury - Linktree
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
So if you want to set it via a variable:
VBSTART
Sub NewDesktopShortcut(strMyPath,linkfile,targetpath,parms,windowstyle,hotkey,iconlocation,descr)
Set WshShell = CreateObject("Wscript.Shell")
set oShellLink = WshShell.CreateShortcut(strMyPath & "\" & linkfile)
oShellLink.TargetPath = targetpath
oShellLink.Arguments = parms
oShellLink.WindowStyle = windowstyle
oShellLink.Hotkey = hotkey
oShellLink.IconLocation = iconlocation
oShellLink.Description = descr
oShellLink.WorkingDirectory = strMyPath
oShellLink.Save
End Sub
VBEND
Let>path=c:\something
VBRun>NewDesktopShortcut,path,etc,etc,etc,
VBSTART
Sub NewDesktopShortcut(strMyPath,linkfile,targetpath,parms,windowstyle,hotkey,iconlocation,descr)
Set WshShell = CreateObject("Wscript.Shell")
set oShellLink = WshShell.CreateShortcut(strMyPath & "\" & linkfile)
oShellLink.TargetPath = targetpath
oShellLink.Arguments = parms
oShellLink.WindowStyle = windowstyle
oShellLink.Hotkey = hotkey
oShellLink.IconLocation = iconlocation
oShellLink.Description = descr
oShellLink.WorkingDirectory = strMyPath
oShellLink.Save
End Sub
VBEND
Let>path=c:\something
VBRun>NewDesktopShortcut,path,etc,etc,etc,
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Awesome Marcus thank you.
I hope you don't think I am just asking you to write code for me without trying myself but in the case of VB I'm afraid there's little else I can do. I am trying my best to learn it though.

I hope you don't think I am just asking you to write code for me without trying myself but in the case of VB I'm afraid there's little else I can do. I am trying my best to learn it though.

Phil Pendlebury - Linktree
Thanks for the examples.
I have a question. How would I set the "Start in" option? I want it to be set to the directory a user selects. E.g. if the app is located in C:\3rdPartyAppFolder\app.exe I want it to be set to C:\3rdPartyAppFolder instead of "C:\Documents and Settings\USER_NAME\Desktop"
I know I can set it like this strDesktop = "C:\3rdPartyAppFolder" by creating the shortcut in the 3rdPartyAppFolder and then moving it to the desktop. But that's not going to work if the 3rdPartyAppFolder is located in C:\Programs Files\3rdPartyAppFolder
Thanks for any help or suggestions.
I have a question. How would I set the "Start in" option? I want it to be set to the directory a user selects. E.g. if the app is located in C:\3rdPartyAppFolder\app.exe I want it to be set to C:\3rdPartyAppFolder instead of "C:\Documents and Settings\USER_NAME\Desktop"
I know I can set it like this strDesktop = "C:\3rdPartyAppFolder" by creating the shortcut in the 3rdPartyAppFolder and then moving it to the desktop. But that's not going to work if the 3rdPartyAppFolder is located in C:\Programs Files\3rdPartyAppFolder
Thanks for any help or suggestions.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
I believe The "Start in" folder you see in shortcuts is stored in the WorkingDirectory property:
oShellLink.WorkingDirectory = strMyPath
oShellLink.WorkingDirectory = strMyPath
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Thanks.
I finally got it to work.
Here is the working code if anyone is interested.
I finally got it to work.
Here is the working code if anyone is interested.
Code: Select all
VBSTART
Sub NewDesktopShortcut(linkfile,targetpath,parms,windowstyle,hotkey,iconlocation,descr,strMyAppFolder)
Set WshShell = CreateObject("Wscript.Shell")
set oShellLink = WshShell.CreateShortcut(strMyAppFolder & "\" & linkfile)
oShellLink.TargetPath = targetpath
oShellLink.Arguments = parms
oShellLink.WindowStyle = windowstyle
oShellLink.Hotkey = hotkey
oShellLink.IconLocation = iconlocation
oShellLink.Description = descr
oShellLink.WorkingDirectory = strMyAppFolder
oShellLink.Save
End Sub
VBEND
Let>shortcut_icon_title=3rd Party App Name
Let>linkfile=%shortcut_icon_title%.lnk
Let>profile=%USER_NAME%
//Save shortcut to specified Folder and set "Start in" variable
let>strMyAppFolder=C:\MyAppFolder
//Let>targetpath=C:\consolegrab\ProfileManager\Profile Manager.exe
Let>targetpath=C:\MyAppFolder\app.exe
//Let>parms=/Profiletouse="%profile%" /Output="Commandline"
Let>parms=
//1=Normal, 3=Maximized, 7=Minimized
Let>windowstyle=1
//Let>hotkey=CTRL+SHIFT+R
Let>hotkey=CTRL+SHIFT+R
//Note: the icon image is contained within the app exe
//Let>iconlocation=C:\consolegrab\ProfileManager\Profile Manager.exe, 0
Let>iconlocation=C:\MyAppFolder\app.exe, 0
//Let>descr=Profile Manager Shortcut
Let>descr=Temp Shortcut
VBRun>NewDesktopShortcut,linkfile,targetpath,parms,windowstyle,hotkey,iconlocation,descr,strMyAppFolder
//Move shortcut to desktop
MoveFile>%strMyAppFolder%\%shortcut_icon_title%.lnk,%DESKTOP_DIR%\%shortcut_icon_title%.lnk