简体   繁体   中英

Visual Basic: Save File with Icon

I am creating a program that copies itself to the desktop with different names. I want to give each file a different icon. I know you can assign an icon to the original file but I want each copy to have a different icon. Is there any way I can do this with code?

FileCopy(System.Windows.Forms.Application.ExecutablePath, "C:\Users\" & System.Environment.UserName & "\Desktop\bob.exe")
FileCopy(System.Windows.Forms.Application.ExecutablePath, "C:\Users\" & System.Environment.UserName & "\Desktop\tim.exe")
FileCopy(System.Windows.Forms.Application.ExecutablePath, "C:\Users\" & System.Environment.UserName & "\Desktop\jeff.exe")

The technique of cloning your .exe programs under different names is probably not a great idea, for example, if you update your app, you'd have a bunch of uncontrolled copies that are not updated on the desktop. Not to mention that modifying exes in this day of viruses and trojans...just bad.

However, you might want to make your app accept command line input so you can make shortcuts to your app with appropriate arguments, such as "bob", "tim", and "jeff" and set the icon. Much safer and more friendly. Here's a link for shortcut creation (it's in C# but can be translated to VB fairly easy): http://www.c-sharpcorner.com/uploadfile/kirtan007/how-to-create-shortcut-of-application-programatically-using-C-Sharp/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM