Dynamically change icon in context menu
Moderator: DosItHelp
Re: Dynamically change icon in context menu
Thanks for your input. Solution complexity should correspond to the task at hand, and switching Current Display sounds straightforward at user level. For now I'd leave it "as is", it works OK though not ideal. Will see if someone can come up with a native Windows Shell solution. Its interesting in general, as many people would benefit from learning how to speed up one's workflow by modifying Context Menu with simple but clever means. Not much about it on the web except basics.
Re: Dynamically change icon in context menu
Can someone point why the above batch PlanIcon.bat worked well in Win 10 64bit, but doesn't work in Win 11 64bit?
Code: Select all
@echo off
:: The batch updates Active Power Plan icon in Desktop Context Menu, when Power Plan is changed. Can run as a scheduled task triggered by EventID 12 "Power Plan changed"
setlocal EnableExtensions EnableDelayedExpansion
set "key=HKCR\DesktopBackground\Shell\Switch Power Plan"
set "plan1=Balanced" & set "plan2=High performance" & set "plan3=Power saver"
set "icon1=powercpl.dll,0" & set "icon2=powercpl.dll,2" & set "icon3=powercpl.dll,1"
for /f "tokens=5,6" %%a in ('powercfg -getactivescheme') do ( set pln1=%%a & set pln2=%%b
if defined pln2 ( set "pln=!pln1:~1!!pln2:~0,-1!" ) else ( set "pln=!pln1:~1,-2!" ))
for %%d in (1 2 3) do ( if !plan%%d!==!pln! ( reg add "%key%" /v Icon /d !icon%%d! /f > nul ))
endlocal
exit /b
Last edited by sambul36 on 30 May 2022 16:20, edited 1 time in total.
Re: Dynamically change icon in context menu
I can't check myself (since i I have no Win11), So i can list only two potential issues i see ad hoc:
penpen
- Microsoft might have changed the GUID of the power plans.
You could compare the GUID used in "ChangePowerPlan.reg" with the GUID listed by following command:If there was a change, then change the "ChangePowerPlan.reg" accordingly and import the new values to the registry (again).Code: Select all
powercfg.exe /L
- Microsoft might have changed the string representation of the active power scheme.
You could check the output of the following command:If there was a change, then change the for/F-loop in the batch accordingly.Code: Select all
powercfg -getactivescheme
penpen
Re: Dynamically change icon in context menu
Thanks for the reply. I checked it out, and apparently these strings remained the same (see screenshot). Further, I can change the powerplan from Context Menu without errors, only changing the relevant icon by the scheduled task gives an error. However, the Task finishes without any errors in the Event Viewer log, but execution of the batch itself gives the unspecified error.
As a side matter, the above .reg file is unable to add the keys to Win 11 HKCU while running without errors, so instead I added the same keys to HKLM by running a corrected .reg file, but it did not affect changing the powerplan from Context Menu, so its OK. While the icon value is supposed to be changed in HKCR, it is added there, but not changed according to current powerplan each time the batch is run. I also tried running the batch from Win 11 C:\ root without success. But it works perfect in Win 10.
As a side matter, the above .reg file is unable to add the keys to Win 11 HKCU while running without errors, so instead I added the same keys to HKLM by running a corrected .reg file, but it did not affect changing the powerplan from Context Menu, so its OK. While the icon value is supposed to be changed in HKCR, it is added there, but not changed according to current powerplan each time the batch is run. I also tried running the batch from Win 11 C:\ root without success. But it works perfect in Win 10.
- Attachments
-
- PlanIcon.bat_Error.jpg (24.22 KiB) Viewed 6104 times
-
- Compare Win 10_11 powerplans.jpg (154.49 KiB) Viewed 6104 times
Last edited by sambul36 on 30 May 2022 13:16, edited 4 times in total.
Re: Dynamically change icon in context menu
Microsoft fundamentally changed the appearance of the context menu of Win 11.
If you want to turn back to the the classic context menu, import this setting and reboot:
classic_context_menu.reg
No guarantee that the power config items are going to appear though. I didn't test it.
Steffen
If you want to turn back to the the classic context menu, import this setting and reboot:
classic_context_menu.reg
Code: Select all
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32]
@=""
Steffen
Re: Dynamically change icon in context menu
Thanks for the suggestion, I already did it to have faster access to main Context menu. The Change Power Plan menu does appear and work the same way in Win 11 as in Win 10 now, except the above icon batch gives unspecified execution error. I wonder if someone is able to test it on a Win 11 64bit US English PC?
Re: Dynamically change icon in context menu
Maybe try to use the full path to the icon.
Steffen
Code: Select all
for %%d in (1 2 3) do ( if !plan%%d!==!pln! ( reg add "%key%" /v "Icon" /t REG_EXPAND_SZ /d "%%SystemRoot%%\System32\!icon%%d!" /f > nul ))
Re: Dynamically change icon in context menu
Yes, it works. Also works this way, and in fact that type name should be in the original batch code for completeness:
Code: Select all
for %%d in (1 2 3) do ( if !plan%%d!==!pln! ( reg add "%key%" /v "Icon" /t REG_EXPAND_SZ /d !icon%%d! /f > nul ))
Re: Dynamically change icon in context menu
IDK. Just tried it and it's been imported w/o problems.
Steffen