Shortcut Argument

Posts 1–6 of 6 · Page 1 of 1
Shortcut Argument
Hi again. I've got another problem in making shortcuts..

Code:
Dim [Object] As Object = CreateObject("WScript.Shell")

            [Shortcut] = [Object].CreateShortcut([ShortcutName])
            [Shortcut].TargetPath = [Filename]
            [Shortcut].WorkingDirectory = [StartUpPath]
            [Shortcut].WindowStyle = 0
            [Shortcut].IconLocation = [Icon]
            [Shortcut].Save()
This is the code I'm using. (Usually, its incomplete but it should be a good information)
I don't know what is the command for the arguments since I'm getting an error of incorrect parameter.

Example Shortcut:
Code:
[Shortcut].TargetPath = "C:\Program Files\Software\Software.exe" C:\Myfile.dll
When I always make shortcuts like that, it happens to be a wrong parameter.

Even I use The code below, it still occurs..
Code:
Dim MyFile As String = "C:\Program Files\Software\Software.exe C:\Myfile.dll"
[Shortcut].TargetPath = MyFile
Any suggestions?
well...opening a program uses :
[highlight=vb.net]
Dim startInfo As New ProcessStartInfo("C:\Program Files\Counter-Strike Source\hl2.exe")
startInfo.Arguments = "-nomaster -game cstrike -nojoy"
Process.Start(startInfo)
[/highlight]

so..play around with it?...

(c/p from post 3 pages back)
Quote Originally Posted by *****179 View Post
well...opening a program uses :
[highlight=vb.net]
Dim startInfo As New ProcessStartInfo("C:\Program Files\Counter-Strike Source\hl2.exe")
startInfo.Arguments = "-nomaster -game cstrike -nojoy"
Process.Start(startInfo)
[/highlight]

so..play around with it?...

(c/p from post 3 pages back)
Sorry but that's not what I'm looking for and I already know that.

What I'm looking is for making a shortcut with an argument that is like in my first post.
Use the IWshRuntimeLibrary.

Know Dot Net - Creating a Desktop Shortcut in .NET Code

The example shows how to add args as well. No need for VB6 code. (Don't forget to include your references is the final release.)

Although if you really want to use VB6 code here's how:

[highlight=vb.net]
Public Shared Sub CreateShortcut(ByVal filePath As String, ByVal shortcutPath As String, ByVal args As String())
Dim wshObj As Object = CreateObject("WScript.Shell")
Dim shortcutObj As Object = wshObj.CreateShortcut(shortcutPath)
shortcutObj.Arguments = """" + String.Join(""" """, args) + """"
shortcutObj.TargetPath = filePath
shortcutObj.WorkingDirectory = IO.Path.GetDirectoryName(shortcutPath)
shortcutObj.Save()

Runtime.InteropServices.Marshal.ReleaseComObject(s hortcutObj)
Runtime.InteropServices.Marshal.ReleaseComObject(w shObj)
shortcutObj = Nothing
wshObj = Nothing
GC.Collect()
End Sub
[/highlight]
Thanks Jason.

Although this is the only code I need to set its arguments.
Code:
shortcutObj.Arguments = """" + String.Join(""" """, args) + """"
Problem is solved..
Quote Originally Posted by nathanael890 View Post
Thanks Jason.

Although this is the only code I need to set its arguments.
Code:
shortcutObj.Arguments = """" + String.Join(""" """, args) + """"
Problem is solved..
Yeah but I thought I may as well just write up an easy method for future readers
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us