473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating a shortcut on the desktop in vb.net

I have been searching for example code that will create a shortcut
link to a file and place it on the desktop. I have searched google and
found a couple examples using the windows scripting object but they do
not seem to work for me. Would someone be kind enough to post some
example code?

thanks!

Jan 19 '06 #1
1 2692
by the way. here is one of the examples I could not get working. vs.net
claimed there were no errors but when I tried to compile and use I got
null pointer exception

Public Function CreateShortCutOnDesktop(ByVal userID As String, _
ByVal passWord As String) As Boolean
Try
Dim DesktopDir As String = _
CType(WshShell.SpecialFolders.Item("Desktop"), String)
Dim shortCut As IWshRuntimeLibrary.IWshShortcut

' short cut files have a .lnk extension
shortCut = CType(WshShell.CreateShortcut(DesktopDir & _
"\MyNewShortcut.lnk"), _
IWshRuntimeLibrary.IWshShortcut)

' set the shortcut properties
With shortCut
.TargetPath = _

System.Reflection.Assembly.GetExecutingAssembly.Lo cation()
.WindowStyle = 1
.Description = "Run Typist Summary"
.WorkingDirectory = DesktopDir
' the next line gets the first Icon from the executing
program
.IconLocation = _

System.Reflection.Assembly.GetExecutingAssembly.Lo cation() & _
", 0"
' the next line sets the userID and passWord into the
shortcut
' as arguments
' which will be read from the command line.
.Arguments = userID & ", " & passWord
.Save() ' save the shortcut file
End With
Return True
Catch ex As System.Exception
' add your error handling here, if any
Return False
End Try
End Function

Jan 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Roy G. Vervoort | last post by:
I would like to create a shortcut on my desktop and be able to start a program (.exe) from the prgram tree (start > Programs > name program). Normally it wil be created with the setup program...
6
by: Todd Peterson | last post by:
I'm encountering some wierd behavior with a <link> tag over an HTTPS connection, vs. an HTTP connection... In an ASP/HTML page on my website, I've add a <link rel="shortcut icon"...> in order to...
4
by: NaterPotater | last post by:
I can't seem to get my head around the Visual Studio's Deployment Projects: I want the user, at install-time, to be able to specify if they want a icon placed on the desktop or not (I'm trying to...
3
by: Marius Rus | last post by:
I have an application write in c# and i want to offer to the user to create himself shortcuts with icons for the main menu items. I will very much appreciate if will receive an helping hand. Thank...
4
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create...
7
by: GrandpaB | last post by:
I would appreciate assistance learning how to create a Desktop shortcut in my setup project. In the left pane of the Setup/File System window I right-clicked User's Desktop. From the contex...
2
by: urrahul | last post by:
Hi All, Iam using the following JavaScript to create desktop shortcut function createShortcut() { if (ActiveXObject) { // Create desktop shortcut WshShell = new ActiveXObject(...
2
bartonc
by: bartonc | last post by:
There are many applets and other goodies on Windows that must be run by using a command: The normal way to access these tools is to go to the Start menu and click Run. Then type in the name of...
15
by: Mike Driscoll | last post by:
Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.