Embedded icon files

Bozz

Member
Joined
Jul 28, 2009
Messages
14
Programming Experience
Beginner
My program toggles an existing IE add-on between enabled and disabled. At the same time, it creates a shortcut to itself in the Quick Launch folder using one of two icons which reflect whether the next click is a toggle on or toggle off. I store the two icons in the same folder as the targeted executable, and everything works fine, but I would rather have these two files embedded. I know how to embed them. The problem is locating them. At the moment I use:

Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
MyShortcut = WshShell.CreateShortcut(QuickLaunchVariable & "\Toggle.lnk")
MyShortcut.TargetPath = path/executable
MyShortcut.IconLocation = path/iconfile

MyShortcut.IconLocation requires a string and I don't know how to get to the location of an embedded file as a string. There is no MyShortcut.Icon which would allow me to simply refer to the embedded file.
 
For an embedded resource, the IconLocation is the name of the executable file itself followed by the resource number. I'm not really sure how those resource numbers relate to .NET apps but you can look that up.

IconLocation Property
 
I might be saying something very dumb here, or it might be a difficult work around for a simpler question, but it's similar to something I had to deal before in the past and I'll tell you how I made it work.

You have 2 options, I will write both just for the sake of the explanation, but I've used one and for your situation I would recommend the other:
1 - the one I used)
the embedded resource is "compiled" with your code and there is no way to access it using a drive path (e.g. "c:/temp/myfiles/something/ico") that is a good option in case you don't want any unauthorized access to your file, and your code should be the only process handling it. That's the default option and to put the resource in a path you need to use the File.IO to write a copy of your resource into the disk.

2 - the one I recommend you to)
when you select the resource file in your Solution Explorer top-right side of the screen, that resource Properties will be shown in the properties box lower-right side of the screen. You're interested in the "Copy to Output directory" property that specifies if the installation will put an actual file in your disk drive accessible by a path. That should guarantee that the file is already there in the same folder of your executable. Then to access that folder simply use "Application.ExecutablePath"

I hope it was clear...
 
For an embedded resource, the IconLocation is the name of the executable file itself followed by the resource number. I'm not really sure how those resource numbers relate to .NET apps but you can look that up.

IconLocation Property
That requires natively embedding a native win32 compiled resource, containing the icons, to the project. I have not found this possible to do with VB Express, but full VS should have a resource editor where you can do it. See for example Embedding Multiple Icons into .NET Executables - CodeProject

About Express, I can have a win32 resource file created, but have not been able to add it to project, not even by manually adding the Win32Resource node instruction to vbproj file. If anyone gets this done it would be interesting to know how (without using manual compilation with switch). Also so that's been said, none of the .Net embedding options I've tried works for this.
 
Thanks all for a timely response. The comments by JohnH and the link were very informative. It looks like I won't be able to do exactly what I want with Express, so I think for now I will go with the second recommendation of Budius.
 
Back
Top