|
-
Jun 15th, 2009, 06:09 PM
#1
Thread Starter
Member
[RESOLVED] Creating short-cuts
I was wondering how i can write a program to create a shortcut in the startup folder of a different program. So i have one program on my computer that should run at startup, i just need another program to create a shortcut to it, and then copy this shortcut into the startup folder. Thanks
-
Jun 15th, 2009, 06:20 PM
#2
Re: Creating short-cuts
Google "vb.net create shortcut"
-
Jun 15th, 2009, 10:29 PM
#3
Re: Creating short-cuts
Creating shortcuts in VB.NET is not simple and requires unmanaged code, i.e. referencing a Windows COM library. If it's not inappropriate, it's far easier to add a Registry entry to the Run key to run your app at startup. It makes it harder, although far from impossible, for the user to edit or delete it, which may be a good thing or a bad thing, depending on the circumstances.
-
Jun 15th, 2009, 11:12 PM
#4
Re: Creating short-cuts
jmc has a good point, you should probably stick to the registry if its just for startup.
But also to prove my point about googling things, very first link.
http://www.tek-tips.com/faqs.cfm?fid=6127
-
Jun 17th, 2009, 06:29 PM
#5
Thread Starter
Member
Re: Creating short-cuts
Yeah I tried the code from the google link
i have heaps of errors. Firstly the bit at the top -
Code:
Imports IWshRuntimeLibrary
has green underline and says - "Namespace or type specified in the Imports 'IWshRuntimeLibrary' doesnt contain any public member or cannot be found.
And there are blue lines underneath wShell and IWshRuntimeLibrary.IWshShortcut
Here is the code
Code:
Imports IWshRuntimeLibrary
Code:
Private Function CreateShortCut(ByVal shortcutName As String, ByVal creationDir As String, ByVal targetFullpath As String, ByVal workingDir As String, ByVal iconFile As String, ByVal iconNumber As Integer) As Boolean
Try
If Not IO.Directory.Exists(creationDir) Then
Dim retVal As DialogResult = MsgBox(creationdir & " does not exist. Do you wish to create it?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo)
If retVal = DialogResult.Yes
IO.Directory.CreateDirectory(creationDir)
Else
Return False
End If
End If
Dim shortCut As IWshRuntimeLibrary.IWshShortcut
shortCut = CType(wShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
shortCut.TargetPath = targetFullpath
shortCut.WindowStyle = 1
shortCut.Description = shortcutName
shortCut.WorkingDirectory = workingDir
shortCut.IconLocation = iconFile & ", " & iconNumber
shortCut.Save()
Return True
Catch ex As System.Exception
Return False
End Try
End Function
-
Jun 17th, 2009, 06:43 PM
#6
Re: Creating short-cuts
Did you read that page and perform the steps that it specifies, particularly steps 2 and 3, or did you just copy and paste the code?
-
Jun 17th, 2009, 06:53 PM
#7
Thread Starter
Member
Re: Creating short-cuts
Copy and Paste
Most is good but there is still this error - "Name wShell is not declared"
in this bit of code -
Code:
shortCut = CType(wShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"),
-
Jun 17th, 2009, 06:53 PM
#8
Re: Creating short-cuts
If you don't follow instructions then it's isn't really surprising it didn't work. That said, it should be noted that the COM component you need to reference is named "Windows Script Host Object Model". Also, it looks like the wShell variable used in that code has not been declared. It should be type IWshShell3.
-
Jun 17th, 2009, 06:58 PM
#9
Thread Starter
Member
Re: Creating short-cuts
 Originally Posted by jmcilhinney
If you don't follow instructions then it's isn't really surprising it didn't work. That said, it should be noted that the COM component you need to reference is named "Windows Script Host Object Model". Also, it looks like the wShell variable used in that code has not been declared. It should be type IWshShell3.
So how do i make the type IwshShell3?
-
Jun 17th, 2009, 08:01 PM
#10
Re: Creating short-cuts
Add the reference. Did you do that?
Just use Dim var As IWshShell3, as usual. (With the Import, of course.)
-
Jun 17th, 2009, 09:52 PM
#11
Thread Starter
Member
Re: Creating short-cuts
So what should my code look like?
could you post an example?
Sorry, i am just a beginner
-
Jun 17th, 2009, 10:22 PM
#12
Re: Creating short-cuts
Your code should look just like that in the example. You just need to go back and add all of the correct references. I would suggest making a new project and going through every step in that link again, this time don't just copy and paste code.
-
Jun 21st, 2009, 05:55 AM
#13
Thread Starter
Member
Re: Creating short-cuts
Ok i've done that and it still has the same error. "Name 'wShell' is not declared."
-
Jun 21st, 2009, 07:38 AM
#14
-
Jun 21st, 2009, 08:14 AM
#15
Thread Starter
Member
-
Jun 21st, 2009, 03:37 PM
#16
Re: Creating short-cuts
The extremely complicated and advanced piece of code you will need is "Dim". 
Add a variable declaration of wShell as type IWshShell3 in your code (class-level).
-
Jun 22nd, 2009, 02:31 AM
#17
Thread Starter
Member
Re: Creating short-cuts
MY GOD how complex
thanks its fine now
-
Jun 22nd, 2009, 02:36 AM
#18
Re: Creating short-cuts
 Originally Posted by TysonJ33T
I taught myself vb, and missed most basics 
Being self-taught doesn't mean you have to have missed out on the basics. I strongly suggest that you find yourself a beginners tutorial and work through it so that you cover those fundamental concepts that you may currently be missing.
-
Jul 4th, 2010, 07:43 AM
#19
Fanatic Member
Re: Creating short-cuts
 Originally Posted by TysonJ33T
MY GOD how complex
thanks its fine now 
it is not clear how you actually solved the issue of adding the reference.
I added the scripting reference but the Imports still gives me an error.
-
Jul 4th, 2010, 03:54 PM
#20
Re: [RESOLVED] Creating short-cuts
Project > Add Reference is how you did it, right?
-
Jul 4th, 2010, 04:51 PM
#21
Fanatic Member
Re: [RESOLVED] Creating short-cuts
 Originally Posted by minitech
Project > Add Reference is how you did it, right?
the only place to add it is in the project properties?
I only found it there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|