Windows : Only Run Install Startup Script if Directory Doesn't Exist

8,688

Solution 1

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

e.g.

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

Solution 2

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

Solution 3

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.

Share:
8,688

Related videos on Youtube

e__
Author by

e__

Updated on September 18, 2022

Comments

  • e__
    e__ almost 2 years

    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?

    • J. Singh
      J. Singh over 12 years
      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.
    • e__
      e__ over 12 years
      It's a batch file, but it doesn't work so to be honest I'm happy to use anything.
    • J. Singh
      J. Singh over 12 years
      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 ;-)
  • mfinni
    mfinni over 12 years
    That does not cover the case of the product already being manually installed.
  • Mitch
    Mitch over 12 years
    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.
  • Rob Moir
    Rob Moir over 12 years
    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.
  • e__
    e__ over 12 years
    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.
  • mfinni
    mfinni over 12 years
    Yup, that's exactly my point.
  • e__
    e__ over 12 years
    Sorry but how would I do that exactly? (And that way would work perfectly)
  • mfinni
    mfinni over 12 years
    Adobe Reader X most assuredly does have an MSI. ftp.adobe.com/pub/adobe/reader/win/10.x/10.0.0/en_US
  • mfinni
    mfinni over 12 years
    Also, 'mseinstall.exe -x' will extract the MSI installers for MSE.
  • mfinni
    mfinni over 12 years
    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.
  • Mitch
    Mitch over 12 years
    Have your script check for a file that's part of the installation and if the file doesn't exist proceed with the install. That would get you around having to drop a flag file.
  • e__
    e__ over 12 years
    But what would I type into the .BAT file to do that?
  • mfinni
    mfinni over 12 years
    FWIW, that script does not give me a syntax error - it works for me on Windows 7.
  • mfinni
    mfinni over 12 years
    Although I'm not sure what you're doing with @CON ...