Macro to set Shortcut.lnk icon

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

Post Reply
mjbrookes
Bronze Member
Bronze Member
Posts: 88
Joined: 2007 Sep 19, 11:24

Macro to set Shortcut.lnk icon

Post by mjbrookes » 2020 Jun 15, 15:04

I have tried to Record-Macro to achieve this but the recording has not achieved more than recording
...COMMAND 32811

I have many shortcuts and I want them to share an Icon located at ... T:\__shared Icons\_Active Icon__Folder Shortcut.ico


If I manually select a shortcut.lnk file
I would like a macro that:-

* Right-Click
**Properties
***Change Icon
****Browse to ...T:\__shared Icons
*****select...T:\__shared Icons\_Active Icon__Folder Shortcut.ico
*****Open
****OK
***Apply
***OK

Thanks for your attention

User avatar
nikos
Site Admin
Site Admin
Posts: 14628
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Macro to set Shortcut.lnk icon

Post by nikos » 2020 Jun 16, 06:21

it appears that the properties dialog opens in a new thread, and as such the macro system cannot operate it, sorry.
however if you have a fixed icon you want for all your shortcuts, you can use a windows script instead (or powershell)
for WSH you need the CreateShortcut method which despite what its name says can also be used to open existing shortcuts. Perhaps it's easier to do with powershell but i'm not a fan/expert there

if you need more information about WSH, I wrote a series of blog articles some time ago, e.g
www.zabkat.com/blog/18Apr10-WSH-arguments.htm

mjbrookes
Bronze Member
Bronze Member
Posts: 88
Joined: 2007 Sep 19, 11:24

Re: Macro to set Shortcut.lnk icon

Post by mjbrookes » 2020 Jun 16, 13:02

Thanks for your reply and in particular for the links to other web pages. I have studied them and other blog posts and googled for help, but despite many attempts am still stuck, and hope someone can help.

I have created a shortcut (with default Icon) ... C:\Users\mjb17\Documents\ShortcutTest.lnk

and created ...
C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs

Code: Select all

objShell = WScript.CreateObject("WScript.Shell")
objShtCut = objShell.CreateShortcut
		("C:\\Users\\mjb17\\Documents\\ShortcutTest.lnk") objShtCut.IconLocation = "C:\Windows\System32\shell32.dll", 2
objShtCut.Save()
WScript.Echo(objShtCut.IconLocation)

but when I open a cmd.exe window, and run >cscript vbs__test__changeIcon.vbs
I get error message
C:\Users\mjb17\Documents>cscript vbs__test__changeIcon.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs(3, 3) Microsoft VBScript compilation error: Expected statement

What I would really like to be able to do is to
in the code ... specify the target-ICON-file as ... A:\xxxx\__shared Icons\_Active Icon__Folder Shortcut.ico
then to use Xplorer2 to select a shortcut.lnk file ... and then run the ChangeIcon code on the selected item.

Thanks

User avatar
nikos
Site Admin
Site Admin
Posts: 14628
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Macro to set Shortcut.lnk icon

Post by nikos » 2020 Jun 16, 14:59

does your ShortcutTest.lnk exist or not?
anyway try the following script instead (notice the formatting and using double \\ inside paths and using SET for assigning objects -- the sample code above is faulty)

Code: Select all

set objShell = WScript.CreateObject("WScript.Shell")
set objShtCut = objShell.CreateShortcut("C:\\Users\\mjb17\\Documents\\ShortcutTest.lnk") 
objShtCut.IconLocation = "C:\\Windows\\System32\\shell32.dll, 2"
objShtCut.Save()
WScript.Echo(objShtCut.IconLocation)
as for adding variability to the script, see the blog post mentioned above

mjbrookes
Bronze Member
Bronze Member
Posts: 88
Joined: 2007 Sep 19, 11:24

Re: Macro to set Shortcut.lnk icon

Post by mjbrookes » 2020 Jun 16, 15:24

Hi Nikos

when I use your code from your reply (thanks for pointing out the need for "double\\")
I get error message
C:\Users\mjb17\Documents>cscript vbs__test__changeIcon__nikos.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\mjb17\Documents\vbs__test__changeIcon__nikos.vbs(1, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'objShell'


C:\Users\mjb17\Documents>
I have experimented when the target-shortcut does exist and when it does not (just in case).

I don't know what I am doing well enough to trouble shoot but I am keen to continue, any more ideas?

regards

User avatar
nikos
Site Admin
Site Admin
Posts: 14628
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Macro to set Shortcut.lnk icon

Post by nikos » 2020 Jun 16, 17:56

I tested the code before I posted it here, and it works for me. Make sure you have it exactly copy/paste as above (except for your own paths)

also keep in mind, that automation is only good if it saves you time and effort. If this is way too deep for you and you have to learn all sorts of new tricks to do a simple task, perhaps it's not worth it for you :)
(unless you like to learn new things)

mjbrookes
Bronze Member
Bronze Member
Posts: 88
Joined: 2007 Sep 19, 11:24

Re: Macro to set Shortcut.lnk icon

Post by mjbrookes » 2020 Jun 17, 09:41

:oops: did a strict cut & paste this morning...and it works
it seems that I had missed the "sets" :oops:

I am now experimenting. :-)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks for your help
also keep in mind, that automation is only good if it saves you time and effort. If this is way too deep for you and you have to learn all sorts of new tricks to do a simple task, perhaps it's not worth it for you :)
(unless you like to learn new things)
it may be quicker to do my changes manually on this occasion, but what about when I change my mind and want something slightly different in the future :D
You are correct that this is currently "too deep" for me and I would need to learn all sorts of new tricks (I have previously never needed to use "automation of DOS commands")

But it seems worthwhile spending 2-3 days to try and increase my knowledge

mjbrookes
Bronze Member
Bronze Member
Posts: 88
Joined: 2007 Sep 19, 11:24

Re: Macro to set Shortcut.lnk icon

Post by mjbrookes » 2020 Jun 17, 16:31

Hi Nikos,

I have made big progress today :-)
sufficient to complete my current tasks,
Thank you for your help.

there are however 3 aspects which I would like to improve:-

Once the Script has finished:-
[1] How can I close the X2-console? or simply return to the x2 window?
[2] How can I automatically refresh the X2-pane-view?

My script works if I use a dynamic shortcut.lnk-file and a fixed-code Icon.ico file,
but fails if I try to make both dynamic
[3] How can I make both dymanic?


this is my test code
(only a few lines actually do anything, the rest is for my understanding)

Code: Select all

REM https://www.zabkat.com/x2h_7.htm  .... Automation of DOS (and windows) commands
REM https://www.zabkat.com/blog/15Feb09-explore-windows-script-host.htm
REM https://www.zabkat.com/blog/21Feb10-WSH-browse-subfolders.htm
REM https://en.wikipedia.org/wiki/Windows_Script_Host


REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM Xplorer2 settings -           (works OK)
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				REM ...create UserCommand...
				REM xplorer2 > Customise > USER-COMMANDS > Add New > Name = SetShortcutIcon 
				REM > Description ======================== $$ "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$Q"
				REM ... note...starting cmd with $$ means I can select multiple Shortcutfiles in a Folder for processing 		

		
				REM ...Addto Toolbars...
				REM xplorer2 > Customise > Toolbars > 0Toolbar
				REM > Available Toolbar buttons = SetChortcutIcon
				REM > AddTo > Current Toolbar Buttons


				REM ...Usage...
				REM Dual Pane View ..... > View > Dual Pane
				REM in Pane-1 "Source"   > select the *.ico file     (becomes InactivePane  $Q=Filename from inactive pane    WScript.Arguments(0) )
				REM switch Panes 
				REM in Pane-2 "Target"   > select Target Shortcut    (becomes ActivePane    $F=Full path name                 WScript.Arguments(1) ) 
				REM Click Toolbar > SetShortcutIcon				




REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM Test for Missing beginning-Parameters -          (works OK)
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if WScript.Arguments.Count = 0 then
   Wscript.Echo "Xplorer2 useage....Active_Pane_select = myTargetShortcutFile..........Inactive_Pane_select = mySelectedIcon "
   wscript.quit
end if




REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM Set Icon-File Source
REM Set Target Shortcut.lnk which will have it's Icon changed
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
myTargetShortcutFile = WScript.Arguments(0)

mySelectedIcon = WScript.Arguments(1)
REM FAILS, continue testing using specific Icon File	
				REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				REM test library of Absolute path-files
				REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				REM myTargetShortcutFile = "C:\Users\mjb17\Documents\ShortcutTest.lnk"
				REM myTargetShortcutFile = "C:\Users\mjb17\Documents\ShortcutTest_2.lnk"
				
				mySelectedIcon = "T:\__shared Icons\_Active Icon__Folder Shortcut.ico"
				
				REM mySelectedIcon = "T:\__shared Icons\diagonal_icon-icons.com_64897.ico"
				REM mySelectedIcon = "T:\__shared Icons\diagonal-2_icon-icons.com_64899.ico"
				REM mySelectedIcon = "T:\__shared Icons\diagonalarrow3_84085.ico"
				
				REM mySelectedIcon = "T:\__shared Icons\double-right-arrows-angles_icon-icons.com_73275.ico"
				REM mySelectedIcon = "T:\__shared Icons\leftarrowsicon_87894.ico"
				REM mySelectedIcon = "T:\__shared Icons\arrow-1_icon-icons.com_71257__32.ico"
				
				REM mySelectedIcon = "T:\__shared Icons\expand_arrows_icon_131539.ico"
				REM mySelectedIcon = "T:\__shared Icons\fast-forward-double-black-arrows-multimedia-symbol_icon-icons.com_73029.ico"
				REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				
				

REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM Do the Work -          (works ok)
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set objShell = WScript.CreateObject("WScript.Shell")
set objShtCut = objShell.CreateShortcut(myTargetShortcutFile) 
objShtCut.IconLocation = mySelectedIcon 
objShtCut.Save()
	




REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM Report results -          (works OK)
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM ...option1...permanent msgBox
REM WScript.Echo(objShtCut.IconLocation)
REM ...option2...temporary msgBox
REM https://www.tek-tips.com/viewthread.cfm?qid=801782
rem createobject("wscript.shell").popup objShtCut.IconLocation, 5, "Script report of selected ICON file", 64
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM outstanding - return to Xplorer2 Active-Pane 
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rem it seems that X2 runs the USER COMMAND and then Opens a console window, which keeps the focus even after script is finished
rem [1] Can I avoid opening console?
rem [2] can I close the console, and If So would this return me to the X2window?
rem [3] can I leave the console window open, and switch to x2 window?
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rem WORK Around........ Ignore the x2CMD-console and continue selecting&processing shortcuts within X2
rem ................... the UserCmd can be applied to multiple selections
rem does not work .... exit
rem does not work .... WScript.Quit
rem does not work .... $ "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$Q" & exit
rem does not work .... 
rem does not work .... 





REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM outstanding - rem once the User-Command-script is finished how can I automatically Refresh the pane view
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rem WORK Around........ Ignore the failure to refresh and display the new icon and continue selecting&processing shortcuts within X2
rem ................... Ctrl+R once finished for a folder , OR exit folder and re-enter folder
rem ................... in this way I can process many folders and many shortcut.lnk before reviewing the results
rem in X2...Ctrl+r ... 59395
rem does not work .... $ "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$Q" & CTRL+R
rem does not work .... $ "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$Q" & 59395
rem does not work .... 
 





REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM possible developments - what about processing Icons in Non-shortcut files?
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~








REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM possible developments - what about processing non-icon file properties?
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User avatar
nikos
Site Admin
Site Admin
Posts: 14628
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Macro to set Shortcut.lnk icon

Post by nikos » 2020 Jun 18, 05:56

1. to get rid of the console window, don't use it in the first place. Instead of $ use > to prompt the VBS command

3. Your script cannot read the second argument (icon) because you use "$Q" which is the filename only; instead use $G which is the full path to the selected item in the inactive pane.

2. you can combine a macro with your script to issue the refresh command, as such:

Code: Select all

POP 0
FINDCLASS Edit # the addressbar
SETTEXT '>wscript "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$G"'
sendkey enter
wait 1500
COMMAND 59395 # refresh

mjbrookes
Bronze Member
Bronze Member
Posts: 88
Joined: 2007 Sep 19, 11:24

Re: Macro to set Shortcut.lnk icon

Post by mjbrookes » 2020 Jun 18, 16:44

Hi Nikos,
Thanks for your Reply

[3] your solution of replacing the Second-parameter "$Q" with "$G" works Brilliantly :-)




[1] my attempts to avoid using the console-window have not worked

using the AddressBar:

$ "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$G"
.......... works OK - for single target-Scortcut.lnk-file and single source.ICO file (but opens console window)

$$ "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$G"
.......... works OK - for MULTIPLE target-Scortcut.lnk-file and single source.ICO file (but opens console window)



> "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$G"
......... Fails to change Icon for target-Scortcut.lnk-file ... and gets error message - CPU tried its best but this command is ineffable

>"C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$G"
......... Fails to change Icon for target-Scortcut.lnk-file ... and gets error message - CPU tried its best but this command is ineffable



>> "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$G"
......... No Console opens, but... Fails to change Icon for MULTIPLE target-Scortcut.lnk-file ... and gets error message - CPU tried its best but this command is ineffable

>>"C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$G"
......... No Console opens, but... Fails to change Icon for MULTIPLE target-Scortcut.lnk-file ... and gets error message - CPU tried its best but this command is ineffable


From what I tried, can you see what I am doing wrong?






[2] I copy&pasted your macro code into a new macro ( now named "Nikos Macro" :-) )
But it does not change the Icons.

Sometines the Macro ends ok, but does not change the icon;
Note in this example
$G = T:\__shared Icons\diagonalarrow_116413.ico
$F = T:\1957-08-25__XXXX-XX-XX__BROOKES Mark Jeremy\__sb2__##self##__1957-08-25__XXXX-XX-XX__BROOKES Mark Jeremy - Shortcut.lnk


other times
the Macro Fails & I get 2 popup windows:
Note in this example
$G = T:\__shared Icons\diagonalarrow_116413.ico
$F = C:\Users\mjb17\Documents\ShortcutTest.lnk

(i)
---------------------------
Windows Script Host
---------------------------
Script: c:\users\mjb17\documents\vbs__test__changeicon.vbs
Line: 66
Char: 1
Error: The shortcut pathname must end with .lnk or .url.
Code: 80020009
Source: WshShell.CreateShortcut

---------------------------
OK
---------------------------


(ii)
---------------------------
xplorer²
---------------------------
Macro stopped execution with error 1 Line: 6 Last argument: 59395
Do you want to debug the macro?
---------------------------
Yes No
---------------------------





I did notice that the Macro code said ... '>wscript "C:\Users\mjb17\Documents\vbs__test__changeIcon.vbs" "$F" "$G"'
but the macro's address bar says......... >wscript "c:\users\mjb17\documents\vbs__test__changeicon.vbs" "$f" "$g"
differences (a) lowercase parameters (b) no enclosing '' commas
my reading of your web page (https://www.zabkat.com/x2h_7.htm) suggests that this should be having no effect, but I did think it was interesting that the parameters got changed.



Thanks for your attention

User avatar
nikos
Site Admin
Site Admin
Posts: 14628
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Macro to set Shortcut.lnk icon

Post by nikos » 2020 Jun 18, 18:17

to run your VBS with arguments you must use the '>wscript xxx.vbs' method.

if you want to debug/troubleshoot scripts, put some wscript.echo(xxx) to see what arguments are passed

finally the conversion to lowercase arguments is a side effect of running inside the macro, but it doesn't cause any problems

mjbrookes
Bronze Member
Bronze Member
Posts: 88
Joined: 2007 Sep 19, 11:24

Re: Macro to set Shortcut.lnk icon

Post by mjbrookes » 2020 Jun 19, 17:38

to run your VBS with arguments you must use the '>wscript xxx.vbs' method.
Thanks, this solved it.
if you want to debug/troubleshoot scripts, put some wscript.echo(xxx) to see what arguments are passed
spent the day experimenting with this
and discovered that the xplorer2 syntax which works for user commands does not work the same for macros.
The problem was with fullFileNames which included spaces,
I discovered that if I add a splattering of ""'s I can get it to work


I now have a scriptLET which achieves all my original objectives, :party:
but getting this far has given me even more ideas :D

Thanks for all your help,

mjbrookes
Bronze Member
Bronze Member
Posts: 88
Joined: 2007 Sep 19, 11:24

Re: Macro to set Shortcut.lnk icon

Post by mjbrookes » 2020 Jun 22, 14:19

So my basic solution:-

1. Select *.ICO file
2. select target-shortcut-file.LNK ... second x2 pane

3. Copy&Paste into Address Bar ============================== >>wscript "Full-Path-and-Filename.vbs" "$G" "$F"
eg ==================================================== >>wscript "A:\_myData\settings__Xplorer2\test.vbs" "$G" "$F"

4. test.vbs

Code: Select all

if WScript.Arguments.Count = 0 then
   	Wscript.Echo "Xplorer2 useage....Active_Pane_select = myTargetShortcutFile..........Inactive_Pane_select = mySelectedIcon "
	   wscript.quit
	end if

	mySourceSelectedIcon = WScript.Arguments(0)
	myTargetShortcutFile = WScript.Arguments(1)

	set objShell = WScript.CreateObject("WScript.Shell")
	set objShtCut = objShell.CreateShortcut(myTargetShortcutFile) 
	objShtCut.IconLocation = mySourceSelectedIcon 
	objShtCut.Save()


but I get nicer xplorer2-usage when I turn the above into a macro


(includes my documentation and ideas)

Code: Select all

REM https://www.zabkat.com/x2h_7.htm  .... Calling DOS & Windows commands from X2 AddressBar
REM https://www.zabkat.com/blog/15Feb09-explore-windows-script-host.htm
REM https://www.zabkat.com/blog/21Feb10-WSH-browse-subfolders.htm
REM https://en.wikipedia.org/wiki/Windows_Script_Host


'	Active Code Below
'~~~~~~~~~~~~~~~~~~~~~~~~
'	if WScript.Arguments.Count = 0 then
'   	Wscript.Echo "Xplorer2 useage....Active_Pane_select = myTargetShortcutFile..........Inactive_Pane_select = mySelectedIcon "
'	   wscript.quit
'	end if
'
'	mySourceSelectedIcon = WScript.Arguments(0)
'	myTargetShortcutFile = WScript.Arguments(1)
'
'	set objShell = WScript.CreateObject("WScript.Shell")
'	set objShtCut = objShell.CreateShortcut(myTargetShortcutFile) 
'	objShtCut.IconLocation = mySourceSelectedIcon 
'	objShtCut.Save()






REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM Xplorer2 notes
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					REM ...Usage...                    (works OK)
					REM DUAL PANE view is assumed/Required
					REM Dual Pane View ..... > View > Dual Pane
				REM in Pane-1 "Source"   > select the *.ico file        (becomes InactivePane  $G=Full-Path-name from INactive pane    WScript.Arguments(0) )
				REM switch Panes 
				REM in Pane-2 "Target"   > select Target Shortcut(s)    (becomes ActivePane    $F=Full-path-name from Active pane      WScript.Arguments(1) ) 
				REM then Run-ScriptLET


				REM option 1         (works OK)
				REM Run (this Visual Basic file) from Address Bar
				REM Copy&Paste into Address Bar ============================== $$ "Full-Path-and-Filename.vbs" "$G" "$F" 		
				REM ... note...starting cmd with $  means I can select a single target-Shortcutfiles for processing 
				REM ... note...starting cmd with $$ means I can select multiple target-Shortcutfiles for processing 
				REM ... note...starting cmd with $$ means xplorer2 will open it's 'Console' Window and switch cursor-focus to it
				REM switch cursor-focus to xplorer2 window 
				REM CTRL+R (menu > View > Refresh) ... to force X2 to display new Icons


				REM option 2         (works OK)
				REM Run (this Visual Basic file) from Address Bar
				REM Copy&Paste into Address Bar ============================== >>wscript "Full-Path-and-Filename.vbs" "$G" "$F"		
				REM ... note...starting cmd with >wscript   means I can select a single target-Shortcutfiles for processing 
				REM ... note...starting cmd with >>wscript  means I can select multiple target-Shortcutfiles for processing 
				REM ... note...starting cmd with >>wscript  means xplorer2 will NOT open it's 'Console' Window, so no need to switch active-window-focus	
				REM CTRL+R (menu > View > Refresh) ... to force X2 to display new Icons



				REM option 3         (works OK)
				REM Run (this Visual Basic file) as an Xplorer2-User_Command
				REM avoids the tedious need to copy & paste the above command into the xplorer2 AddressBar
				REM ...create UserCommand...
				REM xplorer2 > Customise > USER-COMMANDS > Add New > Name = SetShortcutIcon 
				REM > Description ============================================ >>wscript "Full-Path-and-Filename.vbs" "$G" "$F"	
								REM ...Addto Toolbars...
								REM xplorer2 > Customise > Toolbars > 0Toolbar
								REM > Available Toolbar buttons = SetChortcutIcon
								REM > AddTo > Current Toolbar Buttons
		



				REM Optionally         (works ok)
				REM Run (this Visual Basic file) as an Xplorer2-Macro
				REM avoids the tedious need to copy & paste the above command into the xplorer2 AddressBar
				REM avoids also the tedious need to force an xplorer2 screen-refresh
	     		REM ... note ... the xplorer2 parameters need extra """"'s in order to work in macro mode 
				REM ...create Macro...
				REM xplorer2 > Customise > Macros > Edit
				REM copy&paste code below (remove REM's)
							REM POP 0
							REM FINDCLASS Edit # the addressbar
							REM SETTEXT '>>wscript "Full-Path-and-Filename.vbs" ""$G"" ""$F""'
							REM sendkey enter
							REM wait 1500
							REM COMMAND 59395 # refresh
				REM Save > name = ShortcutIcons
				REM Select SourceIcon.file and Target-Shortcut-File(s) then Run macro

			





REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        (works ok)
REM Test for Missing beginning-Parameters - 
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if WScript.Arguments.Count = 0 then
   Wscript.Echo "Xplorer2 useage....Active_Pane_select = myTargetShortcutFile..........Inactive_Pane_select = mySelectedIcon "
   wscript.quit
end if



REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        (not working #####################)
REM Test User-Inputs
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		
'[1] test that source ICON file has extension ".ico"
'		
'				set objTestICO = WScript.Arguments(0)
'				
'				if objTestICO.contains(".ico") = True then
'						Wscript.Echo "Source File is an icon file ...OK ....Inactive_Pane_select = mySelectedIcon ... MUST be an Icon file ... *.ICO"
'				Else
'						Wscript.Echo "Source File is NOT an icon file ...FAILS ....Inactive_Pane_select = mySelectedIcon ... MUST be an Icon file ... *.ICO"
'				   wscript.quit
'				end if
'				
'[2] test that Traget Shortcut-file has extension ".lnk"
'	
'				set objTestLNK = WScript.Arguments(1)
'				
'				if objTestICO.contains(".lnk") = True then
'						Wscript.Echo "Traget File is a Shortcut file ...OK ....... MUST be a shortcut file ... *.LNK"
'				Else
'						Wscript.Echo "Source File is NOT a Shortcut file ...FAILS ....... MUST be a schortcut file ... *.LNK"
'				   wscript.quit
'				end if
'				
				
				




REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        (works ok)
REM Set Icon-File Source
REM WScript.Arguments(0) inhetits the First parameter submitted by xplorer2-involking-command
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mySourceSelectedIcon = WScript.Arguments(0)


REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        (works ok)
REM Set Target Shortcut.lnk which will have it's Icon changed
REM WScript.Arguments(1) inhetits the Second parameter submitted by xplorer2-involking-command
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
myTargetShortcutFile = WScript.Arguments(1)
				








REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        (works ok)
REM Reports and Debugging BEFORE processing
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM ...option1...permanent msgBox
REM WScript.Echo(objShtCut.IconLocation)
REM
REM ...option2...temporary msgBox
REM https://www.tek-tips.com/viewthread.cfm?qid=801782
REM https://www.vbsedit.com/html/f482c739-3cf9-4139-a6af-3bde299b8009.asp
REM 
REM 			createobject("wscript.shell").popup _
REM 			vbcrlf _
REM 			& "message line 1" _
REM 			& vbcrlf _
REM 			& "message line 2" & objShtCut.IconLocation, _
REM 			& vbcrlf _
REM 			timewait seconds, _
REM 			"Title of message box", _
REM 			 Style of buttons
REM

'				createobject("wscript.shell").popup _
'				vbcrlf _
'				& "X2 Inactive Window: Source Icon  == $G ..." & vbcrlf _
'				& "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbcrlf _
'				& "inherited parameter 01.....WScript.Arguments(0) ..." & vbcrlf _
'				& WScript.Arguments(0) & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& "mySourceSelectedIcon ..." & vbcrlf _
'				& mySourceSelectedIcon & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& "X2 Active Window: Target shortcut.LNK file  == $F ..." & vbcrlf _
'				& "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbcrlf _
'				& "inherited parameter 02 .....WScript.Arguments(1) ..." & vbcrlf _
'				& WScript.Arguments(1) & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& "myTargetShortcutFile  ..." & vbcrlf _
'				& myTargetShortcutFile & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				, _
'				1, _
'				"Script report of variables - BEFORE processing", _
'				 64

REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~










REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        (works ok)
REM Do the Work -
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set objShell = WScript.CreateObject("WScript.Shell")
set objShtCut = objShell.CreateShortcut(myTargetShortcutFile) 
objShtCut.IconLocation = mySourceSelectedIcon 
objShtCut.Save()
	




REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        (works ok)
REM Reports and Debugging AFTER processing
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM ...option1...permanent msgBox
REM WScript.Echo(objShtCut.IconLocation)
REM
REM ...option2...temporary msgBox
REM https://www.tek-tips.com/viewthread.cfm?qid=801782
REM https://www.vbsedit.com/html/f482c739-3cf9-4139-a6af-3bde299b8009.asp
REM 
REM 			createobject("wscript.shell").popup _
REM 			vbcrlf _
REM 			& "message line 1" _
REM 			& vbcrlf _
REM 			& "message line 2" & objShtCut.IconLocation, _
REM 			& vbcrlf _
REM 			timewait seconds, _
REM 			"Title of message box", _
REM 			 Style of buttons
REM

'				createobject("wscript.shell").popup _
'				vbcrlf _
'				& "X2 Inactive Window: Source Icon  == $G ..." & vbcrlf _
'				& "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbcrlf _
'				& "inherited parameter 01.....WScript.Arguments(0) ..." & vbcrlf _
'				& WScript.Arguments(0) & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& "mySourceSelectedIcon ..." & vbcrlf _
'				& mySourceSelectedIcon & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& "objShtCut.IconLocation ..." & vbcrlf _
'				& objShtCut.IconLocation & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& "X2 Active Window: Target shortcut.LNK file  == $F ..." & vbcrlf _
'				& "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbcrlf _
'				& "inherited parameter 02 .....WScript.Arguments(1) ..." & vbcrlf _
'				& WScript.Arguments(1) & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& "myTargetShortcutFile  ..." & vbcrlf _
'				& myTargetShortcutFile & vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				& vbcrlf _
'				, _
'				1, _
'				"Script report of variables AFTER processing", _
'				 64
				
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~










REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM possible developments - what about processing Icons in Non-shortcut files/folders?
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rem https://www.activexperts.com/admin/vbscript-collection/filesfolders/folders/#ChangeFolderAttribs.htm







REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REM possible developments - what about processing non-icon file properties?
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User avatar
nikos
Site Admin
Site Admin
Posts: 14628
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Macro to set Shortcut.lnk icon

Post by nikos » 2020 Jun 22, 16:23

:thumbup:

Post Reply