I’ll post another answer summarizing this by just stating what to do.
A few things.
(from what I can tell at least!) anything you drag onto the taskbar, is a shortcut. So whether you drag an EXE, or a VBS or a LNK file, then it if comes up, it comes up as a shortcut on the taskbar.
Knowing that, means there’s a lot less messing around ‘cos a lot less variables to try when things go wrong.
You can test that, by moving the mouse over to one of the pinned icons, it doesn’t matter that a menu comes up when you hover. Then shift right click.
If it says restore, move, size, minimize, maximize, close) then Click Close(which will just close all the windows of it if there are any). if the icon has gone then you didn’t choose a pinned icon, so shift right click a pinned icon. And you get a menu whose last option is «properties» and there’s a shortcut tab. So it’s a shortcut. And that can prove that it is a shortcut.
Any attempt to drag something on from a network drive, fails (this doesn’t matter even if you have a VBS file on a network drive you can still get it to run from the taskbar no problem) That’s just a peculiarity worth knowing.
When you drag a shortcut onto the taskbar, and it makes a new icon appear there, «pinned» to the taskbar, it is creating a new shortcut. The proof of this, is you can delete the shortcut you dragged, and the shortcut on the taskbar will still be there.
And you can shift right click the shortcut on the taskbar, and go to properties.. ignore the shortcut tab, go to the general tab and in the location box it says
C:UsersusernameAppDataRoamingMicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar
or if you want to copy and paste the whole thing.
%userprofile%AppDataRoamingMicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar
Why the path says «internet explorer» is anybody’s guess, but that’s where the taskbar shortcuts are
If you drag a a VBS file, it wants to know whether you are associating it to an already pinned shortcut, chrome or notepad, or if you hover onto the taskbar generally it says «pin to wscript.exe»
and it will create a shortcut to wscript.exe on the taskbar, and if you look at the shortcut of the target you see it will has created it with no parameters!
And if you click the wscript.exe shortcut on the taskbar it brings up «Windows script ost settings» which is what happens when you execute wscript.exe so you’d probably want to add a parameter so the target is like C:WindowsSystem32wscript.exe c:blaha.vbs to execute the vbs file
If you want to have multiple icons on the taskbar, you’ll find that if you drag wscript.exe to the taskbar (or a shortcut to wscript.exe or blah.vbs), it makes a wscript lnk the first time, but the second time it doesn’t. So what you have to do, is change the target of the shortcut to something different from the existing one, before you drag it.
This is the case for anything, so if you have a shortcut for calc.exe, you drag it onto the taskbar and you get an icon for calc.exe there, it works. If you drag the shortcut or further calc.exe shortcuts to it, they don’t go on there, you get a no entry sign. To get it to work, just change the shortcut target slighhtly e.g. change c:windowssystem32calc.exe to c:windowssystem32calc.exe dfdf Then it will go on the taskbar. You can change the icon too.
With wscript, if you want an icon for a.vbs then do wscript a.vbs, as target, drag it on. Do one for wscript b.vbs (by making a shortcut for wscript and changing the target and dragging it on).
Its a bit similar with explorer. If you drag a folder onto the taskbar, while it won’t stop you, it will try to pin it to explorer. If you want a new icon, then create a shortcut to explorer.exe c:blah. So just precede the target of the shortcut with explorer.exe and then as it’s a shortcut and to a target that no existing shortcut has, it goes on there are a new shortcut.
I’ll post another answer summarizing this by just stating what to do.
A few things.
(from what I can tell at least!) anything you drag onto the taskbar, is a shortcut. So whether you drag an EXE, or a VBS or a LNK file, then it if comes up, it comes up as a shortcut on the taskbar.
Knowing that, means there’s a lot less messing around ‘cos a lot less variables to try when things go wrong.
You can test that, by moving the mouse over to one of the pinned icons, it doesn’t matter that a menu comes up when you hover. Then shift right click.
If it says restore, move, size, minimize, maximize, close) then Click Close(which will just close all the windows of it if there are any). if the icon has gone then you didn’t choose a pinned icon, so shift right click a pinned icon. And you get a menu whose last option is «properties» and there’s a shortcut tab. So it’s a shortcut. And that can prove that it is a shortcut.
Any attempt to drag something on from a network drive, fails (this doesn’t matter even if you have a VBS file on a network drive you can still get it to run from the taskbar no problem) That’s just a peculiarity worth knowing.
When you drag a shortcut onto the taskbar, and it makes a new icon appear there, «pinned» to the taskbar, it is creating a new shortcut. The proof of this, is you can delete the shortcut you dragged, and the shortcut on the taskbar will still be there.
And you can shift right click the shortcut on the taskbar, and go to properties.. ignore the shortcut tab, go to the general tab and in the location box it says
C:UsersusernameAppDataRoamingMicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar
or if you want to copy and paste the whole thing.
%userprofile%AppDataRoamingMicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar
Why the path says «internet explorer» is anybody’s guess, but that’s where the taskbar shortcuts are
If you drag a a VBS file, it wants to know whether you are associating it to an already pinned shortcut, chrome or notepad, or if you hover onto the taskbar generally it says «pin to wscript.exe»
and it will create a shortcut to wscript.exe on the taskbar, and if you look at the shortcut of the target you see it will has created it with no parameters!
And if you click the wscript.exe shortcut on the taskbar it brings up «Windows script ost settings» which is what happens when you execute wscript.exe so you’d probably want to add a parameter so the target is like C:WindowsSystem32wscript.exe c:blaha.vbs to execute the vbs file
If you want to have multiple icons on the taskbar, you’ll find that if you drag wscript.exe to the taskbar (or a shortcut to wscript.exe or blah.vbs), it makes a wscript lnk the first time, but the second time it doesn’t. So what you have to do, is change the target of the shortcut to something different from the existing one, before you drag it.
This is the case for anything, so if you have a shortcut for calc.exe, you drag it onto the taskbar and you get an icon for calc.exe there, it works. If you drag the shortcut or further calc.exe shortcuts to it, they don’t go on there, you get a no entry sign. To get it to work, just change the shortcut target slighhtly e.g. change c:windowssystem32calc.exe to c:windowssystem32calc.exe dfdf Then it will go on the taskbar. You can change the icon too.
With wscript, if you want an icon for a.vbs then do wscript a.vbs, as target, drag it on. Do one for wscript b.vbs (by making a shortcut for wscript and changing the target and dragging it on).
Its a bit similar with explorer. If you drag a folder onto the taskbar, while it won’t stop you, it will try to pin it to explorer. If you want a new icon, then create a shortcut to explorer.exe c:blah. So just precede the target of the shortcut with explorer.exe and then as it’s a shortcut and to a target that no existing shortcut has, it goes on there are a new shortcut.
As mentioned in the comments, the code you have there is not a Batch File so creating a toggleicon.BAT file will do nothing as those commands will not be interpreted and probably just error.
The code is actually VBScript which can be executed using either of the two Windows Scripting Host programs
cscript.exe— For executing code using the Windows Console (command prompt)wscript.exe— For executing code using the Windows GUI
Follow these steps to test the code above
-
Rename the file with a
.vbsextension, based on your question I’d suggesttoggleicon.vbs. -
Then run either of the two commands (depending on the requirement define above)
From a Console Window (
cmd.exe) or via a batch file;cscript.exe "toggleicon.vbs"From the Run command (❖ + R) or via a batch file;
wscript.exe "toggleicon.vbs"
Note: If not in the correct path make sure to pass the full path not just the filename.
Update
I just don’t understand why you think that is the answer, the code you provided was straight up VBScript NOT a batch file and placing that in a file with a .BAT extension will just give an error?
This is just nonsense!
Comment by @ace-thanks
I’m making my first batch files today, and have learnt the difference between .bat (batch file) .vbs (visual basic script) and Powershell. Future readers might benefit from knowing this difference. Luckily that script is pretty straight forward enough for me to understand, and although I would mornally agree with Lankymart, Hackoo has provided a more thorough answer to my whole problem, which was outlined in the question. So Vote +1.
If you think you have learnt anything, you are sadly mistaken.
Let’s just analyse the original question…
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:WindowsSystem32SHELL32.dll”, 13 objShortcut.Save
If that is your batch file then running that would give you the following error;
‘objShortcut.Save’ is not recognized as an internal or external command,
operable program or batch file.
This is because objShortcut.Save is VBScript syntax not Batch Command syntax.
There is a really simple way to get this example to work, just rename the file with a .VBS extension as already mentioned and if you really need to execute from a batch write one like this;
Batch file called toggleicon.bat
@ECHO OFF
ECHO.
ECHO "Create Shortcut Example"
ECHO.
cscript.exe /nologo "toggleicon.vbs"
Just make sure both the batch file and the VBScript file are in the same directory when executed.
Я опубликую другой ответ, суммирующий это, просто указав, что делать.
Несколько вещей.
(из того, что я могу сказать по крайней мере!) все, что вы перетащите на панель задач, является ярлыком. Таким образом, независимо от того, перетаскиваете ли вы EXE-файл, VBS или LNK-файл, он появляется в виде ярлыка на панели задач.
Знание этого означает, что гораздо меньше возни, потому что гораздо меньше переменных, которые можно попробовать, когда что-то пойдет не так.
Вы можете проверить это, подведя указатель мыши к одному из закрепленных значков, и не имеет значения, что при всплывающем меню появляется меню. Затем сдвиньте правой кнопкой мыши.
Если там написано: «Восстановить, переместить, изменить размер, свернуть, развернуть, закрыть»), то нажмите «Закрыть» (который просто закроет все его окна, если они есть). если значок исчез, значит, вы не выбрали закрепленный значок, поэтому сдвиньте правую кнопку мыши на закрепленном значке. И вы получите меню, последний вариант которого — «Свойства», и есть вкладка быстрого доступа. Так что это ярлык. И это может доказать, что это ярлык.
Любая попытка перетащить что-либо с сетевого диска завершается неудачей (это не имеет значения, даже если у вас есть файл VBS на сетевом диске, вы все равно можете запустить его с панели задач). Это просто особенность, которую стоит знать.
Когда вы перетаскиваете ярлык на панель задач, и там появляется новый значок, «закрепленный» на панели задач, он создает новый ярлык. Доказательством этого является то, что вы можете удалить ярлык, который вы перетащили, и ярлык на панели задач все еще будет там.
И вы можете сдвигать правой кнопкой мыши ярлык на панели задач и переходить к свойствам. Игнорировать вкладку ярлыков, переходить на вкладку «Общие» и в поле местоположения он говорит
C:Users имя пользователя AppData Roaming Microsoft Internet Explorer Быстрый запуск Пользователь закреплен TaskBar
или если вы хотите скопировать и вставить все это.
% userprofile%AppDataRoamingMicrosoftInternet Explorer Быстрый запуск Пользователь закреплен TaskBar
Почему путь говорит «Internet Explorer» — это чье-то предположение, но вот где ярлыки на панели задач
Если вы перетаскиваете VBS-файл, он хочет знать, связываете ли вы его с уже закрепленным ярлыком, хромом или блокнотом, или если вы наводите курсор на панель задач, как правило, он говорит «прикрепить к wscript.exe» и создаст ярлык для wscript.exe на панели задач, и если вы посмотрите на ярлык цели, то увидите, что он создал ее без параметров!
И если вы щелкнете по ярлыку wscript.exe на панели задач, он вызовет «Настройки ost скрипта Windows», что и происходит, когда вы запускаете wscript.exe, так что вы, вероятно, захотите добавить параметр, чтобы цель была как C:WindowsSystem32wscript.exe c:blaha.vbs для выполнения файла VBS
Если вы хотите иметь несколько значков на панели задач, вы обнаружите, что если вы перетащите wscript.exe на панель задач (или ярлык для wscript.exe или blah.vbs), это сделает wscript lnk в первый раз, но во второй раз это не так. Поэтому вам нужно изменить цель ярлыка на нечто отличное от существующего, прежде чем перетаскивать его.
Это относится ко всему, поэтому, если у вас есть ярлык для calc.exe, вы перетаскиваете его на панель задач и получаете значок для calc.exe, он работает. Если вы перетащите на него ярлык или другие ярлыки calc.exe, они там не будут отображаться, вы получите знак «Нет записи». Чтобы заставить его работать, просто измените цель ярлыка, например, измените c:windowssystem32calc.exe на c:windowssystem32calc.exe dfdf. Затем он перейдет на панель задач. Вы можете изменить значок тоже.
С wscript, если вы хотите значок для a.vbs, тогда сделайте wscript a.vbs, как цель, перетащите его. Сделайте один для wscript b.vbs (сделав ярлык для wscript, измените цель и перетащите ее).
Это немного похоже на проводник. Если вы перетащите папку на панель задач, пока она не остановит вас, она попытается закрепить ее в проводнике. Если вам нужен новый значок, создайте ярлык для explorer.exe c:blah. Так что просто поставьте перед ярлыком цель ярлык с explorer.exe, а затем, если это ярлык, и к цели, которой нет у существующего ярлыка, он продолжает действовать, и появляется новый ярлык.
Задайте вопрос
Быстрый доступ
- Форумы
- Просмотр пользователей форумов
- Часто задаваемые вопросы
Поиск связанных бесед
- Remove From My Forums
Лучший отвечающий
Серверные ОС Windows
>
Windows Scripting
-
Вопрос
-
0
Нужно войти
как изменить изображение ярлыка через vbs?
4 февраля 2009 г. 11:55
Ответить
|
Цитировать
Ответы
-
1
Нужно войти
нашел сам -- object.IconLocation = strIconLocation , всем спасибо
-
Предложено в качестве ответа
Евгений Вековшинин
4 февраля 2009 г. 13:21 -
Помечено в качестве ответа
ILYA [ sie ] SazonovModerator
9 ноября 2010 г. 12:57
4 февраля 2009 г. 12:13
Ответить
|
Цитировать
-
Предложено в качестве ответа

