1

So the goal of this project was to automate a rainmeter skin to extract icons and names from .url and .lnk files on your desktop. (This would than be used later to display icon image as clickable shortcut in a desktop overlay).

Anyway, did a bunch of research, got stuck

First I locate the Desktop folder, which could be on another drive so...

set "DesktopFolder="
for /F "skip=1 tokens=1,2*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop 2^>nul') do if /I "%%I" == "Desktop" if not "%%~K" == "" if "%%J" == "REG_SZ" (set "DesktopFolder=%%~K") else if "%%J" == "REG_EXPAND_SZ" call set "DesktopFolder=%%~K"
if not defined DesktopFolder for /F "skip=1 tokens=1,2*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Desktop 2^>nul') do if /I "%%I" == "Desktop" if not "%%~K" == "" if "%%J" == "REG_SZ" (set "DesktopFolder=%%~K") else if "%%J" == "REG_EXPAND_SZ" call set "DesktopFolder=%%~K"
if not defined DesktopFolder set "DesktopFolder=\"
if "%DesktopFolder:~-1%" == "\" set "DesktopFolder=%DesktopFolder:~0,-1%"
if not defined DesktopFolder set "DesktopFolder=%UserProfile%\Desktop" 

This appears to work.

Than I get a list of items in that directory

set "LIST="
for %%G in (%DesktopFolder%\*.url, %DesktopFolder%\*.lnk) do set LIST=!LIST! %%~nxG

This also appears to work. But appears to be one long string when echoed to a txt file. Which might be a problem.

So also tried

for /F "usebackq tokens=*" %%A in (DirContents.txt) do set LIST=!LIST! %%A

Next I need to feed that list into something else to pull the icons, save them, and name them.

set "exe_in=%LIST%"
set "out_dir=Icons"
set "out_nam=%LIST%"
set "ico_out=%out_dir%\%out_nam%.ico"
set "psCommand1="Remove-Item(\"%ico_out%\")""

set "psCommand2="[void][Reflection.Assembly]::LoadWithPartialName('System.Drawing');^
[Drawing.Icon]::ExtractAssociatedIcon(\"%DesktopFolder%\%exe_in%\").ToBitmap().Save(\"%ico_out%\")""

set "psCommand3="[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"%DesktopFolder%\%exe_in%\").FileDescription""

powershell -noprofile -noninteractive %psCommand1%
powershell -noprofile -noninteractive %psCommand2%
powershell -noprofile -noninteractive %psCommand3%

Still appears to not be able to feed them one at a time and loop until all items are processed and all icon files extracted and named.

Arolust
  • 11
  • 1
  • 4
    Why waste all of those commands trying to determine the path to the users `Desktop`? You clearly already have `PowerShell` because you're using it in the rest of your code, so what is wrong with using something like `(Get-ChildItem -Path ([Environment]::GetFolderPath("Desktop") + "\*") -File -Include "*.lnk", "*.url").Name`. – Compo Nov 04 '21 at 01:38

0 Answers0