Batch file to run a program ONLY if it is installed on the computer

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
vpindori1
Posts: 1
Joined: 26 Feb 2018 03:59

Batch file to run a program ONLY if it is installed on the computer

#1 Post by vpindori1 » 26 Feb 2018 04:07

Hi,

Currently have a .bat file as a User log on startup script in Group Policy to run papercut when a user logs in. Below is what's in the .bat file

Start "" "C:\Program Files (x86)\PaperCut MF Client\pc-client.exe"

This works perfectly fine if the PC has PaperCut MF already installed, however some PC's dont have PaperCut MF installed and gives an error message when the user logs in.

Can this be edited to check if PaperCut MF has been installed/if that location exists and only then run. If its not installed/doesn't exist then don't do anything.

Thanks.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Batch file to run a program ONLY if it is installed on the computer

#2 Post by Squashman » 26 Feb 2018 10:50

Personally I would just redirect the error message to the NUL device. That way it is not seen.

Otherwise a simple IF EXIST command will do the trick.

Type IF /? at the command prompt to view the help for the IF command.

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: help with .bat file

#3 Post by SIMMS7400 » 27 Feb 2018 05:32

Very simple:

Code: Select all

@ECHO OFF

SET "PC_BIN=C:\Program Files (x86)\PaperCut MF Client"

IF EXIST "%PC_BIN%\pc-client.exe" (
	Start "" "%PC_BIN%\pc-client.exe"
)

Post Reply