'Script check app version to trigger action

I want to use GPO deploy log on script for User Configuration to check the McAfee app version, If not installed, go to install If already installed, go to skip

Here is my script putting on log on script,

@ECHO OFF
SETLOCAL
set MA_KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\McAfee\Agent"
set MA_VALUE_NAME=InstallPath

FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (
 `REG QUERY %MA_KEY_NAME% /v %MA_VALUE_NAME% 2^>nul`) DO (
    set Home="%%C"
)

IF DEFINED home SET home=%home:"=%
if defined home echo "already installed"
if NOT defined Home "\\D:\software\MA_IN.exe -s"
exit /b 0

Actually, when script is detected "already installed", I want to check version, when a version >= 5.7.6.251 version go to the end, when a version is low goes to uninstall via command "\\D:\software\MA_UN.exe --noreboot"

I saw detail version in path "C:\Program Files\McAfee\Agent\cmdagent.exe -i", then show output:

Component: McAfee Agent
AgentMode: 2
Version: 5.7.6.251
GUID: aa367df5-56d7-4c0e-bd03-cee30124h4e4
TenantId: 665u9-5A79-4ADA-969B-AB3457C1852
LogLocation: C:\ProgramData\McAfee\Agent\logs
InstallLocation: C:\Program Files\McAfee\Agent\
CryptoMode: 0
DataLocation: C:\ProgramData\McAfee\Agent\
EpoServerList: ah-usg002.mvision.mcafee.com|ah-gw002.mvision.mcafee.com
EpoPortList: 443
EpoServerLastUsed: ah-ghj002.mvision.mcafee.com
LastASCTime: 20220507075931
LastPolicyUpdateTime: 20220507075931
EpoVersion: 5.9.0
ServerId: 8F2DFF36F-8663-4205-BB50-92FF4FB04F73

When user AD (not as administrator) logon, the script will be run but not completed because cannot run as administrator, Please help me at all. Many thanks



Solution 1:[1]

This will check the version. If it is lower than the given version, it will uninstall it. If it does not find the version, it will install it and if the version is equal to or larger than the given version, it will just skip any install or uninstall.

@echo off
for /f "tokens=3*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Application Plugins\EPOAGENT3000" ^| findstr "Version"') do set "ver=%%i"
if not defined ver "D:\software\MA_UN.exe" -s
if defined ver if %ver% LSS 5.7.6.251 "D:\software\MA_UN.exe" --noreboot & goto :EOF

As for the Admin rights, you will need to control the installation with the policies.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gerhard