MSFN Forum: Simple Batch 'IF' script - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Simple Batch 'IF' script just cant get it working Rate Topic: -----

#1 User is offline   a_user 

  • Group: Members
  • Posts: 5
  • Joined: 10-January 08

Posted 13 March 2009 - 05:37 PM

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.


#2 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,019
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 13 March 2009 - 08:04 PM

Cmd promt not my best but give this a try

Quote

@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


#3 User is offline   MHz 

  • SendToA3X v1.7
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,634
  • Joined: 02-August 04

  Posted 14 March 2009 - 04:40 AM

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.

#4 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 14 March 2009 - 05:53 AM

What about gettting rid of live update too!
MsiExec /norestart /q/x"{76B2BC31-2D96-4170-9C44-09E13B5555F3} REMOVE=ALL"
"%ProgramFiles%\Symantec\LiveUpdate\LSETUP.EXE" /U


#5 User is offline   a_user 

  • Group: Members
  • Posts: 5
  • Joined: 10-January 08

Posted 14 March 2009 - 08:21 AM

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.

This post has been edited by a_user: 14 March 2009 - 08:40 AM


#6 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 14 March 2009 - 08:57 AM

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!

#7 User is offline   a_user 

  • Group: Members
  • Posts: 5
  • Joined: 10-January 08

Posted 16 March 2009 - 01:26 PM

Yes thank you. Makes for a very clean removal. Again, appreciate all the help!

#8 User is offline   tech_moron 

  • Group: Members
  • Posts: 2
  • Joined: 02-October 09

Posted 02 October 2009 - 06:21 PM

View PostYzöwl, on Mar 14 2009, 09:57 AM, said:

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

#9 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 04 October 2009 - 08:16 AM

I'd suggest you remove LU after having removed the Symantec product(s), however it shouldn't be necessary.

#10 User is offline   tech_moron 

  • Group: Members
  • Posts: 2
  • Joined: 02-October 09

Posted 05 October 2009 - 10:47 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy