Help deleting a specific desktop icon

What if you want to delete something that may contain certain words, since users might had changed the actual name. can it be?

delete "{pathname of files whose (name of it equals "*CMS*.lnk") of folder (value of variable "allusersprofile" of environment & "\Desktop")}"

assuming that

So you want to delete any desktop shortcut that contains CMS in the name of it?

That is possible, but you can also delete a desktop shortcut based upon the TARGET of the shortcut, which is much less likely to be changed.

  • Can you describe the situation and what you are trying to accomplish?
  • Do you want to delete the shortcut from just the public desktop? Or any user desktop? or any user desktop PLUS the public desktop?

Related:

There is a bunch of different content related to shortcuts and desktop shortcuts on https://bigfix.me

Thank you jgstew, Im trying to delete any shortcut that connects to “C:\program files (x86)\Avaya\CMS Supervisor R14\ASCRun.exe” whether is in the default,public or user specific desktop.
And at the same time create a new one that will target "C:\program files (x86)\Avaya\CMS Supervisor R18\ASCRun.exe"
I will read thru the content you linked, I’m still pretty new to BigFix. I’m creating everything thru the Wizard for applications

1 Like

This what Im trying to do. still working on it. I’m trying to understand the coding behind the ones you linked.

for:
dos del {("%22" & it & "%22") of concatenation "%22;%22" of pathnames of descendants whose(name of it as lowercase ends with ".lnk" AND name of it as lowercase contains "uninstall") of folder ((it as string) of value "Common Start Menu" of key "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" of native registry)}

what if is upper case? what does %22 mean? Im trying to do Desktop. so Im thinking more like. this I what I put together in a batch.

Del /q "C:\Users\%username%\Desktop\" *CMS*.lnk
Del /q "C:\Users\Default\Desktop\" *CMS*.lnk
Del /q "C:\Users\Public\Desktop\" *CMS*.lnk
xcopy "C:\Users\%username%\Appdata\Roaming\Avaya\CMS Supervisor R14\Profiles\" "C:\Users\%username%\Appdata\Roaming\Avaya\CMS Supervisor R18\Profiles\" \Y \E
xcopy "C:\Program Files (x86)\Avaya\CMS Supervisor R14\Profiles\" "C:\Users\%username%\Appdata\Roaming\Avaya\CMS Supervisor R18\Profiles\" \Y \E 

so how would I transmit this to Action language that BigFix uses

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

I wish it was a typo. by the way thanks for the explanation! this is helping me so I can put stuff together my self. I’m still trying to make sense of it.

appendfile xcopy "C:\Program Files (x86)\Avaya\CMS Supervisor R14\Profiles" {concatenation "%0d%0a" of ( %22 "CMS Supervisor R14\Profiles%22 %22") 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)) } /Y /E

Im trying to understand is why there is a %22 here ("del /q %22" & it & "%22")
if I understood correctly

For DOS
%22 = "
%25 = %
%0d%0a = /

therefore

{concatenation "%0d%0a" of ("xcopy %22" & it & "CMS Supervisor R14\Profiles%22 %22" & it & "\CMS Supervisor 18\Profiles%22 /Y /E") = /xcopy “CMS Supervisor R14\Profiles” “\CMS Supervisor 18\Profiles” /Y /E

I’m trying to understand the & it & I’m assuming it set for the variable after the parenthesis

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)) } = & it & ?

so can I make a line that goes:

appendfile xcopy "C:\Program Files (x86)\Avaya\CMS Supervisor R14\Profiles" {concatenation of ( & it & " %22" & it & "\CMS Supervisor 18\Profiles%22") 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 know its there is something (or a lot) wrong here since I’m getting Error in the debugger.

Also it failed to deploy :frowning:

I think you’re getting close though, just need to relate how “it” gets substituted and how the concatenations work. Try these statements in the fixlet debugger, I think it’ll help illustrate how this statement gets evaluated:

q: value "ProfilesDirectory"  of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" of native registry as string

q: expand environment string of (value "ProfilesDirectory"  of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" of native registry as string)

q: folders (expand environment string of (value "ProfilesDirectory"  of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" of native registry as string))

q: 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))

q: 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))

q: ("Here's a result:" & it) 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))
 --> This will fail because "it" is a Folder, not a String, and you can't concatenate a folder.
q: ("Here's a result:" & it) 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))

q: ("MANAGING FOLDER %22" & it & "%22") 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))

q: ("xcopy  %22" & it & "%22 %22" & it & "%22") of pathames 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))

q: ("xcopy  %22" & it & "\CMS Supervisor R14\Profiles%22 %22" & it & "\CMS Supervisor R18\Profiles%22") 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))

q: concatenation "%0d%0a" ("xcopy  %22" & it & "\CMS Supervisor R14\Profiles%22 %22" & it & "\CMS Supervisor R18\Profiles%22") 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))
1 Like

Not sure if the { } are supposed to work with a specific version of BigFix, We are running 9.1.1117.0 - Cant upgrade it cause our Windows team lost the password to the main.

We are not really providing finished code at this point, so make sure you are very careful about this.

I’d recommend creating the situation on a VM or on a machine you have direct access to and testing in the Fixlet Debugger to see if the relevance and actionscript work correctly / as expected.

Once you have relevance working you can test it in an Analysis to see what it tells you about the situation on other machines. It can help you know how many machines are affected.

Once you have things working on the action side in the fixlet debugger / command line, only then does it make sense to test through bigfix, and generally only on some test machines until you are satisfied that it works well.

thank you jgstew, I dont mean to be a pest. I do test everything in some test equipment I have.
I placed the code in the debugger and it went fine. somestuff failed when I was doing that QnA, but I am looking into why it fails in there and not in the action section of the debugger.

Im asking in the forum to learn more as the Bigfix training provided to my team had little to do with actions and I want to go that extra mile.

I do appreciate all the input given and Jason has tough me a lot. not sure how the full code would look like. nonetheless, if you can direct me to a manual that has all these language and code. I would appreciate it. I did look at https://bigfix.me/learn and https://developer.bigfix.com/action-script/guide/ but the https://bigfix.me/learn I was not able to pullthe .pdf

1 Like

https://developer.bigfix.com is definitely the best resource in general. The basics of actionscript are fairly straightforward, but adding in relevance substitution is a bit tricky, but also what makes it more powerful.

If you are more comfortable with something like PowerShell or VBScript, you could write a solution in that and then run it with BigFix using something like createfile. See this example: https://bigfix.me/fixlet/details/3860

Writing the relevance to detect files on systems that have the issue you are trying to address is not too difficult and I think @JasonWalker already has you covered most of the way there if not completely. You should be able to put it into an analysis to get an idea of how many systems have this issue.

Figuring out the actionscript to do exactly what you need will take a bit more effort, and not something I have time for at the moment, but hopefully you’ll get there with help from many of us & the documentation. It can be overwhelming the first time around, but it gets easier over time.

It should be as simple as deleting any shortcut pointing to C:\program files (x86)\Avaya\CMS Supervisor R14\ASCRun.exe if that file no longer exists and then add a shortcut to C:\program files (x86)\Avaya\CMS Supervisor R18\ASCRun.exe if that file exists, which could be 2 separate fixlets/tasks.

Do you need to maintain the shortcut name if the user has changed it or is it acceptable to blindly delete any that are no longer needed and add back the new one if missing with a generic name? It is definitely easiest if you don’t have to be fancy about it.

Some more info about the desired end result in general and if it can be the same for everyone would be useful.


the {} are for relevance substitution. It definitely works for v8+ and probably older, but it can be tricky to get just right.

Lost the password to the Root Server private key? That is going to be a big problem at some point. You will probably need to backup all custom content and set up a brand new root server, then do a masthead migration thingy to get all of your clients to talk to the new root server instead of the old one. You will loose your audit trail and other things on the new system because I don’t think you are going to be able to migrate the database without that password, though I’m not certain. I’d definitely recommend working with IBM on that at some point.