Jump to content

Simple Batch 'IF' script


Recommended Posts

I know Im probably missing something very simple but Im amature when it comes to batch scripting. What I am trying to do is this. Remove symantec, Then check if sophos is installed (doing this by looking for a particular file in the sophos installation directory) if exists do nothing, if not exist then install.

%windir%\system32\msiexec.exe /q /x {76B2BC31-2D96-4170-9C44-09E13B5555F3} /norestart

IF EXIST ""C:\Program files\Sophos\savmain.exe" goto end

\\ln-co-avs01\InterChk\ESXP\setup.exe -mng yes -user domain\username -pwd Pass#123 -s

exit

i can get it to uninstall symantec and then install sophos but it keeps reinstalling sophos to a client that already has it installed.

your help would be greatly appreciated.

Link to comment
Share on other sites


Cmd promt not my best but give this a try

@Echo Off
CLS
Color f5
Mode 62,7
Title Anti Virus Change Brand

Set Sophos="C:\Program files\Sophos\savmain.exe"

If Exist %Sophos% Goto Work1
If Not Exist %Sophos% Goto Work2

:Work1
CLS
Echo.
Echo Confirm %Sophos%
ping -n 3 127.0.0.1>nul
Goto TheEnd

:Work2
Cls
Echo.
Echo Preparing To Unistall Symantec
Start /W %windir%\system32\msiexec.exe /q /x {76B2BC31-2D96-4170-9C44-09E13B5555F3} /norestart
CLS
Echo.
Echo Preparing To Install Sophos
Start /W \\ln-co-avs01\InterChk\ESXP\setup.exe -mng yes -user domain\username -pwd Pass#123 -s
CLS
Echo.
Echo Completed Sophos Install
ping -n 3 127.0.0.1>nul
Goto TheEnd

:TheEnd
Exit

Link to comment
Share on other sites

Another option. Using CMD in WinNT based systems is safe to use multiline statements so this avoids the goto feature.

%systemroot%\system32\msiexec.exe /q /x {76B2BC31-2D96-4170-9C44-09E13B5555F3} /norestart
If Not Exist "%Programfiles%\Sophos\savmain.exe" (
\\ln-co-avs01\InterChk\ESXP\setup.exe -mng yes -user domain\username -pwd Pass#123 -s
)

Using Start /Wait is another option that gunsmokingman mentions that could be needed though I test without first up to see if successful.

You can use the command 'If /?' at a command prompt to learn the usage of 'If'. 'Goto' is rather redundant in many of the latest programming languages so is perhaps good to avoid using if possible IMO unless you service 9x or earlier systems with scripts.

Link to comment
Share on other sites

Hey Guys,

Thanks a ton for your replies and help. Especially to gunsmokingman. That worked perfectly! Yzowl, I added your line to remove liveupdate as well.

Thanks again guys for the quick and thorough explanations.

Edited by a_user
Link to comment
Share on other sites

You may wish to add the /q switch too:

MsiExec /norestart /q/x"{76B2BC31-2D96-4170-9C44-09E13B5555F3} REMOVE=ALL"
"%ProgramFiles%\Symantec\LiveUpdate\LSETUP.EXE" /U /q

BTW did you notice the REMOVE=ALL I added to your uninstallation command line!

Link to comment
Share on other sites

  • 6 months later...
You may wish to add the /q switch too:
MsiExec /norestart /q/x"{76B2BC31-2D96-4170-9C44-09E13B5555F3} REMOVE=ALL"
"%ProgramFiles%\Symantec\LiveUpdate\LSETUP.EXE" /U /q

BTW did you notice the REMOVE=ALL I added to your uninstallation command line!

Pardon my ignorance. In the above example for removing live update, where should that be placed in the script?

Is it after %systemroot%\system32\msiexec.exe /q /x {123456} /norestart ?

Thank you in advance

Link to comment
Share on other sites

Thank you, Yzowl.

One more question: do I need the quoation marks in the below statement - e.g. " " ?

MsiExec /norestart /q/x"{76B2BC31-2D96-4170-9C44-09E13B5555F3} REMOVE=ALL"

"%ProgramFiles%\Symantec\LiveUpdate\LSETUP.EXE" /U /q

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...