batch-file - 当图标位于快捷方式旁边时如何为快捷方式文件创建图标
问题描述
我想为快捷方式文件选择一个图标。
该文件必须在每台计算机上运行,但图标文件路径可能不同。
我尝试使用此代码更改图标属性:
"%windir%\system32\cmd.exe /c echo "%CD%\1.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 脚本!
快捷方式制作器.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
快捷阅读器.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。
推荐阅读
- javascript - 模块中的 Node.js 函数返回一个空对象
- sql - 占用 200 Mb 的空数据库
- php - 如何在php中更改按钮颜色?
- wagtail - 如何音译 Wagtail CMS 中的 url 页面
- r - 使用 parLapply 并行调用 as.data.frame
- python - 圆上随机点之间的最短距离?
- asp.net - 尝试使用 Web 服务
- python - 按关键字和组结果对行进行排序
- javascript - 如何仅从以下 json 查询中提取 closePrice?
- google-cloud-platform - 如何使用 Google Cloud HTTP(S) 负载平衡器在两个 Cloud Run 服务之间进行渐进式流量迁移