[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Script that creates a flag after installation. Need it to check the path. if not there then install else skip.

Hi,

Script that creates a flag after installation. Need it to check the path. if not there then install else skip.
Instead of the inf file creating and checked i want the program files folder path checked. If there skip. else install.

regards
Sharath
@echo off 
setlocal 
set SourceFolder=\\in1\NETLOGON\Msi
set LogFolder=C:\Temp1
if exist %windir%\installflag211.inf goto END 
if not exist "%LogFolder%" md "%LogFolder%" 
  
set LogFile=%ComputerName%-%~n0.log 
>"%LogFolder%\%LogFile%" echo Source folder directory listing: 
dir "%SourceFolder%" >>"%LogFolder%\%LogFile%" 2>&1 
if errorlevel 1 ( 
  >>"%LogFolder%\%LogFile%" echo No access to source folder, leaving script. 
  goto :eof 
) 
  
set LogFile=%ComputerName%-snapclient.log 
msiexec /i "%SourceFolder%\snapclient.msi" /qn /Lv* "%LogFolder%\%LogFile%" 
set EL_CT=%errorlevel% 
  
  
>>"%LogFolder%\%ComputerName%-Results.log" echo %Date% %Time% Errorlevel snapclient:  %EL_CT% 
>>"%SourceFolder%\Logs\%ComputerName%-Results.log" echo %Date% %Time% Errorlevel snapclient:  %EL_CT% 
 
set /a EL = EL_CT + EL_WST 
if %EL%==0 ( 
  echo "Snap App is installed" > %windir%\installflag211.inf 
  cacls "C:\Program Files\Snap Communications Client" /t /c /e /g users:F 
  del "%LogFolder%\%ComputerName%-snapclient.log" 
  del "%LogFolder%\%ComputerName%-Results.log" 
)
  
:END

Open in new window

0
bsharath
Asked:
bsharath
  • 8
  • 7
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
u can check if it's already installed by 2 ways:
1. registry - under HKLM\software\microsoft\windows\currentversion\uninstall
2. run msiexec and if %errorlevel% is 1638, that means already installed
0
 
bsharathAuthor Commented:
1. Can it check the registry
That would be better

I will have situation as.
there is a new Msi built. At that times i need it reinstalled. in such case what can be done.?
0
 
Meir RivkinFull stack Software EngineerCommented:
u might install it under HKEY_CURRENT_USER\Software\Microsoft\Installer\Products
depends of the installation type (User Only/Everyone)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
bsharathAuthor Commented:
Everyone on the machines will have access and can use
0
 
Meir RivkinFull stack Software EngineerCommented:
>>here is a new Msi built. At that times i need it reinstalled. in such case what can be done.?

it depends if reinstallation is possible.
u might need to uninstall it first and then try reinstall it.

to check if entry exists in registry use the following:

reg query HKEY_CURRENT_USER\Software\Microsoft\Installer\Products /v INSTALLER_NAME || echo Does not Exist!!!!
0
 
bsharathAuthor Commented:
Can we have the program files folder as the check point instead of the flag that creates not nor the registry.
if folder exists then do nothing else install
0
 
Meir RivkinFull stack Software EngineerCommented:
u can't be sure that the installer created a folder under program files, it's not a good reference for installation.
the registry is must more reliable.
0
 
bsharathAuthor Commented:
If you change the script to check the registry value then will it install and upgrade msi when needed. Or will it skip when found a version already exists.?
0
 
Meir RivkinFull stack Software EngineerCommented:
if it is the same version it will skip the installation and move to the next one, but again it depends what u trying to achieve.
u can check in the registry if the version is older than the installer and in that case u might want to uninstall current version and then install the new one.
0
 
bsharathAuthor Commented:
Oik can i get the registry check update in the script
0
 
Meir RivkinFull stack Software EngineerCommented:
what would u want to check in the registry?
0
 
bsharathAuthor Commented:
Oops you told that we could check in registry if the Application is installed. if installed do nothing else install. As i use this in a Login script
0
 
Meir RivkinFull stack Software EngineerCommented:
can u check in the registry where the installation information is located.
is it under HKLM\software\microsoft\windows\currentversion\uninstall?
0
 
bsharathAuthor Commented:
Yes i have it
{31EC18FB-53CF-11DD-8F86-0016D4EF12CC}

MsiExec.exe /X{31EC18FB-53CF-11DD-8F86-0016D4EF12CC}

0
 
Meir RivkinFull stack Software EngineerCommented:
before u copy/paste the script below, pls make the following adjustments.
1. replace <CURRENT_INSTALLED_VERSION> with the version u wish to find.
2. replace the XXX.msi with the installer path.

basically, it checks whether the app version is installed, if true, uninstall it and then next line should be installation of the newer msi version.


@Echo Off
Setlocal
Set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Set "key=%key%\{31EC18FB-53CF-11DD-8F86-0016D4EF12CC}"
For /f "tokens=3 delims=    " %%# In (
  'Reg query "%key%" /v DisplayVersion^|Find "REG_" 2^>Nul') Do Set "rel=%%#"

If [%rel%]==[<CURRENT_INSTALLED_VERSION>] Start "" /wait MsiExec.exe /X{31EC18FB-53CF-11DD-8F86-0016D4EF12CC}

Start "" /wait XXX.msi

Endlocal
Goto :Eof



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now