Link to home
Start Free TrialLog in
Avatar of dierdan
dierdan

asked on

desktop shortcut

How do I create a new shortcut on the Win 95 Desktop from within my VB5  created application ? I need to add a user name as a command-line parameter after the first usage of my application.
Avatar of Ruchi
Ruchi

Ruchi Do you work for Yahoo?.......
You got a really fast search......


;->
Jkunal..Nope, I don't work for Yahoo ;-)
That was just a comment for you search speed........

;->
jkunal... always keep vbnet handy - the code library answers a heck of a lot of the questions posted here <smile>
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
 There's another sample at:

www.thescarms.com
Avatar of Ark
Hi
The easiest way is to use Windows Scripting Host. Take a look at http://support.microsoft.com/support/kb/articles/Q244/6/77.ASP. Sample 2 show, how to add command line parameter. Cheers
Hi
Here is code you want:
'Make reference (VB Menu -> Project -> Reference) to Windows Scripting Host

Private Sub Command1_Click()
   Dim wshShell As New IWshShell_Class
   Dim wshNetwork As New IWshNetwork_Class
   Dim oMyShortCut As IWshShortcut_Class
   Dim sDeskTop As String, sUserName As String
   sDeskTop = wshShell.SpecialFolders.Item("Desktop")
' Set your shortcut name
   Set oMyShortCut = wshShell.CreateShortcut(sDeskTop + "\MyTest.lnk")
'Set window style
   oMyShortCut.WindowStyle = 7 ' &&Minimized 0=Maximized  4=Normal
'Set icon for your shortcut
   oMyShortCut.IconLocation = "d:\vb50\graphics\icons\computer\msgbox01.ico"
'Set target app
   oMyShortCut.TargetPath = "c:\Windows\calc.exe"
'Get user name
   sUserName = wshNetwork.UserName
'Set arguments for shortcut
   oMyShortCut.Arguments = sUserName
'Set working directory
   oMyShortCut.WorkingDirectory = "c:\windows"
'Save shortcut
   oMyShortCut.Save
End Sub
Cheers
Avatar of dierdan

ASKER

I was overwelmed by good answers and references. I choose this one because I cohld easily try it ( and it did excactly what I wanted) and it is the most elegant.Thanks to you all and special thanks to mcrider.
Thanks for the points! Glad I could help!


Cheers!®©