If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Change Shortcut Properties/Icon

I put this example together to demonstrate how to programmatically access a shortcut in
the Program Files Start Menu. With variations of this code you can gain access to any property of a
shortcut. I hope members enjoy this code and post replies of what you think of it.

This demo will change the properties for Internet Explorer in your Start Menu > Program Files.
Comments: the tooltip and comment description for the link.
Arguments: it wil add an argument to the shortcut target.
ShowCommand: it will set the window show state to Maximized
SetIconLocation: it will change the location of the icon to use and designate the icon index to use.
Save: Saves the changes to the shortcut.
InvokeVerb: runs the open command (optionally by uncomenting the line of code)

Re: Change Shortcut Properties/Icon

You need to add the reference to 'Microsoft Shell Controls And Automation
(C:\Windows\System32\Shell32.dll) to your project so it knows how Shell32 is defined.

Also, the constants are how you can determine where your link is located.

The ssfPROGRAMS constant tells the program that the link is going to be in
the Program Files Start Menu. I havent got it all down yet but it would be
nice to get it to work for desktop shortcut creation/modification.

Re: Change Shortcut Properties/Icon

In the Object Browser (press F2) it will allow you to browse through the
object referenced in your project. The const.'s seem to follow the CLSID_ ...
constants for other functions like the SHBrowseForFolder API.

Re: Change Shortcut Properties/Icon

No, I havent had time. I've been writting another CodeBank entry and a few
examples for some members. Plus working on my .NET Control. Perhaps we should
start another thread? This thread is just for code examples.

Re: Change Shortcut Properties/Icon

Ok, this update is for Remix. I figured out the issue of not being able to attach to the Desktop. Turns out that you can not use the .ParseName function on virtual directories. Since the Program Files Start Menu is a file system directory it works but on the Desktop virtual directory it fails with a return of Nothing.

Re: Change Shortcut Properties/Icon

Re: Change Shortcut Properties/Icon

I realize this is an old tread but I have a question as I am trying to use it in my application. I have an icon on my desktop called "Agent Prospecting Presentation", I want to chnage the target path from this:

Re: Change Shortcut Properties/Icon

Hey there . I hope no one minds me bumping a thread from 2 months ago. I adapted this code for myself and it worked great, so thanks.

But one thing i was wondering about is it's only compatible with .lnk shortcuts. While oFolderItem.IsLink will return true for both a .lnk and a .pif, it is only compatible with .lnk's.

So when oFolderItem is equal to a .pif file, (take for example "Aladdin.pif"), it crashes at the code "oShellLink = oFolderItem.GetLink", telling me that it could not find the specified file.

(Even though my profile says .NET 2002 it's based on this code so vb6 code is fine)

Just to fill you's in about the program i'm making, It's called shortcutter. Given a "Game Folders" directory (a folder in which there are folders for every game inside) and a "Shortcut Destination" directory, it finds all the executables for any game in that folder (one game at a time), and accurately predicts which is the main game executable (and if you click accept, or you can choose a different executable from the listview), it creates a shortcut for you. This way you can make shortcuts to abt 50 games in under a minute, so i find it quite useful.

So what i am trying to get it to do now is, at the user's choice, ignore making shortcuts for games that already have one in the "Shortcut Destination" directory.

But yeah, half of them are shortcuts to dos games which presents a problem.
So does anyone know how to make this code compatible with .pif's?

Re: Change Shortcut Properties/Icon

Just because i still like some of the old platform games, and shortcuts to those games become Pifs. See my folder structure is that all my games are installed to C:\Games\Files & a shortcut to every game is in C:\Games. I like it that way.

But yeah that's why. I was afraid you might say that, about shell32 not supporting pifs. Well if you can point me to where i could find something that might help please let me know.

I've thought about it and i'm going to be directing most dos games through dosbox now, which is a win32 app so i probably wont have many .pifs at all after i do that (except for the ones i can't get to work properly in there), so it might not matter so much afterall.

But thanx for any help

[Just editing this to make it clearer. In order to ignore previously made shortcuts, it needs to read the target paths of every shortcut file in the "shortcut destination" directory, so that it can compare those paths to the game executables it finds so it know's when to skip. That's when pifs come into it. But like i said, may not matter so much and thanks for any help )

Re: Change Shortcut Properties/Icon

I must be doing something wrong. I only want to look at the ShortCut (ink) files, but this returns all files...If oFolder.Items.Item(i) = "Form1" Then
If in put in..Form1.ink", the loop passes it over.
I just want the ShortCut files...Thanks

Re: Change Shortcut Properties/Icon

Rob, what I have noticed, you keep coding the .ext...If oFolder.Items.Item(i) = "Form1.ink" Then
But , oFolder.Items.Item(i)...does not return an .ext only the name.
yet, with the .IsLink, I am finding the file.

VB Code:

For i = 0To oFolder.Items.Count - 1

Debug.Print oFolder.Items.Item(i), oFolder.Items.Item(i).IsLink

'Grab only lnk files

If oFolder.Items.Item(i).IsLinkThen

If oFolder.Items.Item(i) = "Form1"Then

Set oFolderItem = oFolder.Items.Item(i)

bFound = True

ExitFor

EndIf

EndIf

Next

Just to clean this code up, will "Shell" accept a path ?
Similar to FSO...lookup?
meaning, I could FSO...lookup = true
then pass the path to Shell
OR, we have to the For/next loop and check every file?

Re: Change Shortcut Properties/Icon

I think I understand about virtual directories. These directories are actually in the XP data base. Although we see them in the Windows Explore, and they look like real folders, they are not? FSO has a lookup and open, oShell.open path..?
...The more I know...the less I know, Author unknown

Re: Change Shortcut Properties/Icon

Hello there,
I have the below code which changes any shortcut's target and arguments on the user's startmenu in multiple profiles. I am facing a problem here i could only change the target but not the arguments any help is appriciated.

Set oShell = New Shell32.Shell
Set oFolder = oShell.NameSpace(ssfDESKTOP)
If (Not oFolder Is Nothing) Then
Dim oFolderItem As Shell32.FolderItem
Set oFolderItem = oFolder.ParseName("Opera.lnk")
If (Not oFolderItem Is Nothing) Then
Dim oShellLink As ShellLinkObject
Set oShellLink = oFolderItem.GetLink
If (Not oShellLink Is Nothing) Then
'aq simba.ge
oShellLink.Arguments = "http://simba.ge/"
oShellLink.Save
End If
Set oShellLink = Nothing
End If
Set oFolderItem = Nothing
End If
Set oFolder = Nothing
Set oShell = Nothing

'----- firefox )) -----------

Set oShell = New Shell32.Shell
Set oFolder = oShell.NameSpace(ssfDESKTOP)
If (Not oFolder Is Nothing) Then
Dim oFolderItem2 As Shell32.FolderItem
Set oFolderItem2 = oFolder.ParseName("Mozilla Firefox.lnk")
If (Not oFolderItem2 Is Nothing) Then
Dim oShellLink2 As ShellLinkObject
Set oShellLink2 = oFolderItem2.GetLink
If (Not oShellLink2 Is Nothing) Then
oShellLink2.Arguments = "http://simba.ge/"
oShellLink2.Save
End If
Set oShellLink2 = Nothing
End If
Set oFolderItem2 = Nothing
End If
Set oFolder = Nothing
Set oShell = Nothing

'----- google chrome-----

Set oShell = New Shell32.Shell
Set oFolder = oShell.NameSpace(ssfDESKTOP)
If (Not oFolder Is Nothing) Then
Dim oFolderItem3 As Shell32.FolderItem
Set oFolderItem3 = oFolder.ParseName("Google Chrome.lnk")
If (Not oFolderItem3 Is Nothing) Then
Dim oShellLink3 As ShellLinkObject
Set oShellLink3 = oFolderItem3.GetLink
If (Not oShellLink3 Is Nothing) Then
oShellLink3.Arguments = "http://simba.ge/"
oShellLink3.Save
End If
Set oShellLink3 = Nothing
End If
Set oFolderItem3 = Nothing
End If
Set oFolder = Nothing
Set oShell = Nothing