当图标在快捷方式旁边时如何为快捷方式文件创建图标

How to create an icon for shortcut file when the icon is next to the shortcut

我想为快捷方式文件选择一个图标。

该文件必须在每台计算机上运行,但图标文件路径可能在每台计算机上都不同。

我试过这段代码来更改图标属性:

"%windir%\system32\cmd.exe /c echo "%CD%.ico""

但是没有用!

所以基本上,您想要做的是在没有用户交互的情况下创建一个带有自定义图标和路径的快捷方式,对吗?

我们可以使用 VBS 代码来执行此任务。我相信在 Windows 8 / 8.1 / 10 中它略有不同,如果有任何问题请告诉我,但是,我记得 Windows 7:

中的 VBS
Set WshShell = CreateObject ("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") \ You can delete the code and just put like 'strDekstop = "X:\User\Desktop"' if you want.
Set Shortcut = WshShell.CreateShortcut(strDesktop + "\ShortcutName.lnk")
Shortcut.WindowStyle = "3" 
Shortcut.IconLocation = "X:\YourIcon.ico"
Shortcut.TargetPath = "X:\YourPath\OrFolder\yourarchive.exe"
ShortCut.Hotkey = "ALT+CTRL+F" // You can just delete this line if you don't want a hotkey.
ShortCut.Save

如果你想要更自动化的东西,我们可以把它变成一个 bat 脚本,没有问题!

快捷方式maker.bat

@echo off
@chcp 1252 >nul
:: By Katorn Hypno
:: Never use quotation marks.
:loop
:: Configs and info above.

:: Command section bellow

:: Asking for directions.
:: Don't forget the executable name and the .exe.
set /p targetpath=Target Path+Executable: 
:: Don't forget the .ico at the end with the icon name.
:: You can put lnklocation and the iconlocation on top of ":loop" for a single ask.
set /p iconlocation=Icon Location: 
set /p lnklocation=Shortcut Location: 
set /p lnkname=Shortcut Name: 

:: Writing VBS file and creating Shortcut.
echo Trying to write...
set katorn=%random%
echo >>%katorn%.vbs Set WshShell = CreateObject ("Wscript.Shell")
echo >>%katorn%.vbs strDesktop = "%lnklocation%"
echo >>%katorn%.vbs Set Shortcut = WshShell.CreateShortcut(strDesktop + "\%lnkname%.lnk")
echo >>%katorn%.vbs Shortcut.WindowStyle = "3" 
echo >>%katorn%.vbs Shortcut.IconLocation = "%iconlocation%"
echo >>%katorn%.vbs Shortcut.TargetPath = "%targetpath%"
echo >>%katorn%.vbs ShortCut.Save
:: You can comment the next line if you don't want to execute the VBS files.
cscript %katorn%.vbs
:: You can uncommment the next line if you want to delete after executing.
:: del /q /f %katorn%.vbs
echo Done.
goto loop

快捷方式Reader.bat

@echo off
@chcp 1252 >nul
set /p folder=VBS archives folder:
:: Uncomment the code bellow to try every possibility.
:: set /l %%w in (0,1,99999) do (
:: cscript %%w.vbs
:: )
:: echo All trys got executed. 99999.
for /d %%w in (%folder%\*) do (
cscript %%w.vbs
 )
echo Done.
pause;

希望对您有所帮助,
K.