使用VBScript或批量更改快捷方式图标 [英] Using VBScript or batch to change Shortcut Icon

查看:435
本文介绍了使用VBScript或批量更改快捷方式图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个批处理文件,将切换从icon0桌面快捷方式图标,ICON1并再次打开第二个执行。

I'm trying to create a batch file that will toggle a desktop shortcut icon from icon0 to icon1 and back again on second execute.

桌面快捷方式指向桌面/ toggleicon.BAT批处理文件(批处理文件在同一目录),但我具有改变第一次执行该图标的第一阶段的麻烦。

The Desktop Shortcut points to the batch file in Desktop/toggleicon.BAT, (Batch files is in same directory) but I'm having trouble at the first stage of changing the icon on first execute.

这是我的code在批处理文件:

This is my code in the batch file:

Const DESKTOP = &H10&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(DESKTOP)
Set objFolderItem = objFolder.ParseName("Shortcut.lnk")
Set objShortcut = objFolderItem.GetLink
objShortcut.SetIconLocation "C:\Windows\System32\SHELL32.dll", 13
objShortcut.Save

我想我只是谷歌搜索错误的事情。

I imagine I'm simply googling the wrong thing.

如果你知道整个code,真棒。如果你能与当前code有助于获得图标改变那么这是太伟大,我当然会标记为解决方案等。

If you know the whole code, awesome. If you can help with the current code to get the icon changing then that's great too, of course I'll mark as solution etc.

推荐答案

这一批code,它生成一个VBScript来在桌面上创建一个快捷方式使用图标,可当你调用这个子这样随时更改方式:

This a batch code that generate a vbscript to create a shortcut on your desktop with icon that can be changed any time when you call this sub like this way :

Call:CreateShortcut "%windir%\system32\calc.exe" "Calculatrice" "Winver.exe,0"

Call:CreateShortcut "%windir%\system32\calc.exe" "Calculatrice" "%Windir%\System32\moricons.dll,6"

整批脚本测试:

@echo off
Title Create a shortcut on your Desktop with icon that can be changed any time by Hackoo
mode con cols=75 lines=3 & color 9B
Call:CreateShortcut "%windir%\system32\calc.exe" "Calculatrice" "Winver.exe,0"
echo(
echo                Hit any key to change the icon shortcut....
pause>nul
Call:CreateShortcut "%windir%\system32\calc.exe" "Calculatrice" "%Windir%\System32\moricons.dll,6"
cls & color 9E
echo(
echo                   The icon shortcut has been changed...
echo                Hit any key to change the icon shortcut....
pause>nul
Call:CreateShortcut "%windir%\system32\calc.exe" "Calculatrice" "%Windir%\System32\SHELL32.dll,13"
cls & color 9D
echo(
echo                   The icon shortcut has been changed...
echo                Hit any key to change the icon shortcut....
pause>nul
Call:CreateShortcut "%windir%\system32\calc.exe" "Calculatrice" "%Windir%\System32\SHELL32.dll,14"
cls & color 9F
echo(
echo                   The icon shortcut has been changed...
pause>nul
Exit /b
::****************************************************************************************************
:CreateShortcut <ApplicationPath> <ShortcutName> <Icon>
(
echo Call Shortcut("%~1","%~2","%~3"^)
echo ^'**********************************************************************************************^)
echo Sub Shortcut(ApplicationPath,Name,Icon^)
echo    Dim objShell,DesktopPath,objShortCut,MyTab
echo    Set objShell = CreateObject("WScript.Shell"^)
echo    MyTab = Split^(ApplicationPath,"\"^)
echo    If Name = "" Then
echo    Name = MyTab(UBound^(MyTab^)^)
echo    End if
echo    DesktopPath = objShell.SpecialFolders("Desktop"^)
echo    Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Name ^& ".lnk"^)
echo    objShortCut.TargetPath = Dblquote^(ApplicationPath^)
echo    ObjShortCut.IconLocation = Icon
echo    objShortCut.Save
echo End Sub
echo ^'**********************************************************************************************
echo ^'Fonction pour ajouter les doubles quotes dans une variable
echo Function DblQuote(Str^)
echo    DblQuote = Chr(34^) ^& Str ^& Chr^(34^)
echo End Function
echo ^'**********************************************************************************************
)> Shortcutme.vbs
Start /wait Shortcutme.vbs
Del Shortcutme.vbs
Exit /b
::****************************************************************************************************

这篇关于使用VBScript或批量更改快捷方式图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆