// Uninstall IntelliJ IDEA from various directories
waithidden cmd /c (for /d %d in (“C:\Program Files\JetBrains\IntelliJ Idea Community Edition*”) do @if exist “%d\bin\uninstall.exe” “%d\bin\uninstall.exe” /S)
waithidden cmd /c (for /d %d in (“C:\Program Files\JetBrains\IntelliJ Idea Community Edition*”) do @if not exist “%d\bin\uninstall.exe” rd /s /q “%d”)
waithidden cmd /c (for /d %d in (“C:\Program Files (x86)\JetBrains\IntelliJ Idea Community Edition*”) do @if exist “%d\bin\uninstall.exe” “%d\bin\uninstall.exe” /S)
waithidden cmd /c (for /d %d in (“C:\Program Files (x86)\JetBrains\IntelliJ Idea Community Edition*”) do @if not exist “%d\bin\uninstall.exe” rd /s /q “%d”)
waithidden cmd /c (for /d %d in (“C:\ProgramData\JetBrains\IntelliJ Idea Community Edition*”) do @if exist “%d\bin\uninstall.exe” “%d\bin\uninstall.exe” /S)
waithidden cmd /c (for /d %d in (“C:\ProgramData\JetBrains\IntelliJ Idea Community Edition*”) do @if not exist “%d\bin\uninstall.exe” rd /s /q “%d”)
waithidden cmd /c (for /d %u in (“C:\Users*”) do (for /d %d in (“%u\AppData\Local\JetBrains\IntelliJ Idea Community Edition*”) do (if exist “%d\bin\uninstall.exe” (“%d\bin\uninstall.exe” /S) else (rd /s /q “%d”))))
waithidden cmd /c (for /d %u in (“C:\Users*”) do (for /d %d in (“%u\AppData\Local\JetBrains\IdeaIC*”) do (if exist “%d\bin\uninstall.exe” (“%d\bin\uninstall.exe” /S) else (rd /s /q “%d”))))
waithidden cmd.exe /C for /f “tokens=*” %i in (‘reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall /s /f “IntelliJ Idea Community” ^| findstr “HKEY_”’) do reg query “%i” /v DisplayVersion | findstr “DisplayVersion” && for /f “tokens=3” %j in (‘reg query “%i” /v DisplayVersion’) do @if %j lss 242.23726.103 reg delete “%i” /f
// Download and install new IntelliJ IDEA version
prefetch ideaIC-2024.2.4.exe sha1:2012483a791e033998361bb22cf2dd57ffecd8f5 size:642555424 //bfix:52311/swd/Packages/ideaIC-2024.2.4.exe sha256:b4e09701a59e3411ffc20b11f72f636117dde1115e0caacf5782c20210708d98
wait __Download\ideaIC-2024.2.4.exe /S
FYI the command that is in BOLD is throwing exit Code 1 when run through Bigfix but it is running with exit code 0 on Fixlet Debugger. Urgent help needed.
Nice use of Batch loops, haven’t seen that in a while.
The problem you’ll encounter though is that in the Fixlet Debugger, the process is running as “you” and is seeing “your” HKEY_CURRENT_USER hive. When run in the BESClient itself, the process is the LocalSystem account and will see LocalSystem’s HKEY_CURRENT_USER hive, which may not give the results you’re expecting. You may have to further loop through ‘keys of key “HKEY_USERS”’ instead of relying on the HKCU mount alias.
Thanks for the suggestion i am doing that only but after the uninstallation we have stale registry values left which is creating reoccurring of action as relevance is able to detect the lower version still installed on the device which is actually not present and the application is getting installed again and again as we are pushing this as policy action.
Now i am using the command given below which is working as expected and deleting the stale registry value but still throwing exit code 1. what can be the reason for that ?
waithidden cmd.exe /C for /f "tokens=*" %u in ('reg query HKEY_USERS') do @for /f "tokens=*" %i in ('reg query "%u\Software\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "IntelliJ Idea Community" ^| findstr "HKEY_"') do @reg query "%i" /v DisplayVersion | findstr "DisplayVersion" && for /f "tokens=3" %j in ('reg query "%i" /v DisplayVersion') do @if %j lss 242.23726.103 reg delete "%i" /f
I think you’d have to run that on a command line and see what, if any, error message is thrown. I don’t have those registry keys present to test for you.
// Loop through all user profiles
waithidden cmd.exe /C for /f "tokens=*" %i in ('reg query "HKU"') do @(
// Check if the IntelliJ IDEA Community registry key exists
for /f "tokens=*" %k in ('reg query "%i\Software\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "IntelliJ Idea Community" ^| findstr "HKEY_"') do @(
// Get the DisplayVersion
for /f "tokens=3" %j in ('reg query "%k" /v DisplayVersion') do @(
// Compare the version and delete if less than 242.23726.103
if %j lss 242.23726.103 reg delete "%k" /f
)
)
)
I don’t have this app installed, but I suggest using the following action script to delete the stale registry key for all users:
I think you left your answer off @divyam.maithani but also I think I see where you’re going with this.
@Ashwin, check whether this relevance query gives you the keys to delete in the Fixlet Debugger:
Q: pathnames of keys whose (name of it starts with "IntelliJ Idea Community" and value "DisplayVersion" of it as string as version < version "242.23726.103") of keys "Software\Microsoft\Windows\CurrentVersion\Uninstall" of keys of keys "hkey_users" of native registry
If so, you could probably change your command… (I’d still recommend you just build a batch file for these multiple commands, but you could conceivably do)
waithidden cmd.exe /C "{concatenation " & " of ("reg delete %22" & it & "%22 /f) of (pathnames of keys whose (name of it starts with "IntelliJ Idea Community" and value "DisplayVersion" of it as string as version < version "242.23726.103") of keys "Software\Microsoft\Windows\CurrentVersion\Uninstall" of keys of keys "hkey_users" of native registry)} "