1

I want to install some programs via a startup script, but once it has run for the first time it'll just reinstall wasting time and overwriting. It's a Server 2008 R2.

Somewhere I found this

IF NOT "C:\Program Files\Microsoft Security Client"=="" 
(
    echo "Already Installed"
) 
else 
(
    "\\192.168.1.104\Programs\Microsoft Security Essentials\Microsoft Security Essentials.exe" /s /runwgacheck
)

IF NOT "C:\Program Files (x86)\Adobe\Reader 10.0"=="" 
(
    echo "Already Installed"
) 
else 
(
    "\\192.168.1.104\Programs\Adobe Reader\AdbeRdr1012_en_US.exe" /sAll /rs /msi EULA_ACCEPT=YES
)

But it doesn't work. How could I get it to?

3
  • What scripting language is this supposed to be? It doesn't appear to be valid Windows .BAT file syntax, or VBscript, or Jscript, or PowerShell.
    – rmalayter
    Jan 30, 2012 at 20:01
  • It's a batch file, but it doesn't work so to be honest I'm happy to use anything.
    – e__
    Jan 30, 2012 at 20:06
  • Yes, you need to use "IF NOT EXIST" in batch files to test for file or direcotory existence, and get rid of the =="" part. I just voted Josh's answer below up. I didn't even recognize it was a batch file because of that, I thought it was Kixtart or some other obscure scripting tool. (Of course .BAT is a "weird" language too, but it is not obscure ;-)
    – rmalayter
    Jan 30, 2012 at 22:12

5 Answers 5

10

You need IF EXIST instead of just IF for batch programming.

e.g.

IF NOT EXIST "C:\Program Files\Microsoft Security Client" (
  :: Install product
)
4

Since you're running AD, why don't you try distributing these products via MSI and GPO?

4
  • 1
    I'm glad I'm not the only person who thinks this every time I read yet another post about how to install stuff with a GPO-based startup script.
    – Rob Moir
    Jan 30, 2012 at 20:00
  • Because these programs don't have an MSI Installer. I've done it with Chrome and Handbrake, but it's not possible to do it for these.
    – e__
    Jan 30, 2012 at 20:06
  • 1
    Adobe Reader X most assuredly does have an MSI. ftp.adobe.com/pub/adobe/reader/win/10.x/10.0.0/en_US
    – mfinni
    Jan 30, 2012 at 20:34
  • Also, 'mseinstall.exe -x' will extract the MSI installers for MSE.
    – mfinni
    Jan 30, 2012 at 20:41
2

Have your script drop a flag, create a text file or something, when the install completes that your script will look for on the subsequent runs. If it finds the flag it ends the process and doesn't re-install. If the flag doesn't exist it completes the install.

12
  • That does not cover the case of the product already being manually installed.
    – mfinni
    Jan 30, 2012 at 19:53
  • Correct. But if I read his question he says he wants to install something, then once it has run not have it run again the next time the startup script runs. If he wants to check for something that may already be installed prior to this he's going to have to add more checks to his process.
    – Mitch
    Jan 30, 2012 at 19:56
  • Yup, that's exactly my point.
    – mfinni
    Jan 30, 2012 at 20:32
  • 1
    Ed - he's saying that when one of your installer BAT files successfully installs a product (CHECK FOR RETURN CODES!), you can have it leave a file on the machine that indicates success. Next time the BAT runs, if it sees that file there, it would just exit (or continue) at that point. But if you can get the syntax for checking for a file, you should also be able to get the syntax for checking for a folder, which is what you were first asking for. Spend some time boning up on your BAT file skills.
    – mfinni
    Jan 30, 2012 at 20:43
  • 2
    Ed, this is not the best place to ask people to line-by-line troubleshoot your scripts. Start simple - write a BAT with a single action and see if that works as expected. Change one thing at a time. Go from there.
    – mfinni
    Jan 30, 2012 at 21:37
0

To test if a directory exists test for the presence of the "nul" file. This will work in BAT and CMD scripts on ANY Windows version.

Just testing for the folder itself often fails, especially if the folder is on a network-drive or accessed by UNC path.

Like this:

if exists c:\somedir\nul (
  echo folder somedir exists in c:\
)

You can also use the trick to see if a drive-letter is in use or not. E.g if exists z:\nul will return true if z: is mapped on a network drive or if it is a DVD-drive, even if there is no disk in the drive.

0

It's 2015, check out some PowerShell.

if (!(Test-Path -Path "$Env:ProgramFiles\Microsoft Security Client" )) {

Write-Host "Not Installed, Installing..."
iex "\\192.168.1.104\Programs\Microsoft Security Essentials\Microsoft Security Essentials.exe /s /runwgacheck"

}

if (!(Test-Path -Path "${Env:ProgramFiles(x86)}\Adobe\Reader 10.0" )) {

Write-Host "Not Installed, Installing..."
iex "\\192.168.1.104\Programs\Adobe Reader\AdbeRdr1012_en_US.exe /sAll /rs /msi EULA_ACCEPT=YES"

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .