Help deleting a specific desktop icon

Sorry for the long-windedness, but there’s a lot of interesting stuff going on in this post.

%22 is translated to a doublequote character. In string constants, any “%” encountered will translate the following two characters as the hexadecimal value of an ASCII character, in this case 0x22 = doublequote. This is very common in relevance, as are %25 - which translates to the “%” character, and “%0d%0a” which translates to Carriage Return / Line Feed - the DOS End-of-Line character pair.

Rather than reading the registry to pull the path of “Common Start Menu”, I usually prefer to use the “csidl folder (integer)” inspector, which helps to “future-proof” the code. CSIDLs are described at https://msdn.microsoft.com/en-us/library/windows/desktop/bb762494(v=vs.85).aspx. The easiest way, I think, to get a listing of them is in the Fixlet Debugger:

q: (it, csidl folders (it)) of (integers in (1,100))
A: 2, C:\Users\Jason\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
A: 5, C:\Users\Jason\Documents
A: 6, C:\Users\Jason\Favorites
A: 7, C:\Users\Jason\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
A: 8, C:\Users\Jason\AppData\Roaming\Microsoft\Windows\Recent
A: 9, C:\Users\Jason\AppData\Roaming\Microsoft\Windows\SendTo
A: 11, C:\Users\Jason\AppData\Roaming\Microsoft\Windows\Start Menu
A: 13, C:\Users\Jason\Music
A: 14, C:\Users\Jason\Videos
A: 16, C:\Users\Jason\Desktop
A: 19, C:\Users\Jason\AppData\Roaming\Microsoft\Windows\Network Shortcuts
A: 20, C:\Windows\Fonts
A: 21, C:\Users\Jason\AppData\Roaming\Microsoft\Windows\Templates
A: 22, C:\ProgramData\Microsoft\Windows\Start Menu
A: 23, C:\ProgramData\Microsoft\Windows\Start Menu\Programs
A: 24, C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
A: 25, C:\Users\Public\Desktop


So you can get the All User’s Desktop with “csidl folder 25”, regardless of whether it’s “Documents and Settings\All Users\Desktop”, “\Users\Public\Desktop”, or wherever. csidl folder 23 is also handy for finding the shared Start Menu which seems to keep moving around on different versions of Windows.

But csidl folders aren’t going to work in this case, as there’s no CSIDL that expands to \Users\Default. There’s a handy registry key value at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList, ‘ProfilesDirectory’, which expands to “C:\Users” or “C:\Documents and Settings” or even, I think, “C:\Profiles” if your OSes go that far back. You can query that with

q: expand environment string of (value “ProfilesDirectory” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList” of native registry as string)
A: C:\Users
I: singular string

You won’t be able to use %username%, because the BigFix client is running in SYSTEM context and not in user context; %username% only exists for the logged-on user. Instead you’ll just need to look through each folder beneath C:\Users

As jgstew says, you can also query for the target of a shortcut, with pathname of shortcut of file.
You can match your filename pattern with find files "<pattern>" of folder, which is not case-sensitive, so you can use find files "*CMS*.lnk" of folder

Ok, so to put that together. If you assume the shortcut has “CMS” in the filename, and it points to “C:\program files (x86)\Avaya\CMS Supervisor R18\ASCRun.exe”, and it’s contained in the “Desktop” subfolder of a User/Default/Public profile, you should be able to get a list of those shortcuts with

q: pathnames of find files "*cms*.lnk" whose (pathname of shortcut of it as lowercase = "C:\program files (x86)\Avaya\CMS Supervisor R18\ASCRun.exe" as lowercase) of folders "Desktop" of folders of folders (expand environment string of (value "ProfilesDirectory" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" of native registry as string))

(Try that out in the Fixlet Debugger on a machine that has the shortcuts and make sure it works the way you expect).

Assuming that works, I think the best way to handle this in Action Script is … to build & execute a batch file

action uses wow64 redirection false
delete __appendfile

// This will build a list of "del /q " lines, one for each bad desktop shortcut
appendfile {concatenation "%0d%0a" of ("del /q %22" & it & "%22") of pathnames of find files "*cms*.lnk" whose (pathname of shortcut of it as lowercase = "C:\program files (x86)\Avaya\CMS Supervisor R18\ASCRun.exe" as lowercase) of folders "Desktop" of folders of folders (expand environment string of (value "ProfilesDirectory"  of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" of native registry as string))}

// This will build a list of "copy R14 profiles to R18 profiles commands.  Only subdirectories of the Users folder, which contain a "AppData\Roaming\Avaya" folder are included.
appendfile {concatenation "%0d%0a" of ("xcopy %22" & it & "CMS Supervisor R14\Profiles%22 %22" & it & "\CMS Supervisor 18\Profiles%22 /Y /E") of pathnames of folders "Appdata\Roaming\Avaya" of folders of folders (expand environment string of (value "ProfilesDirectory"  of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" of native registry as string)) }

// I assume your last copy was a typo and you want to copy the profiles from R14 to R18 beneath Program Files (x86).  Since there's no relevance substitution here we can use doublequotes directly rather than %22
appendfile xcopy "C:\Program Files (x86)\Avaya\CMS Supervisor R14\Profiles" "C:\Program Files (x86)\Avaya\CMS Supervisor R18\Profiles" /Y /E

//move the __appendfile we've been generating to a batch file & execute it
delete RemoveShortcuts.cmd
move __appendfile RemoveShortcuts.cmd
waithidden cmd.exe /c RemoveShortcuts.cmd
3 Likes