Video Screencast Help

if a file exists return code 1 and dont run rest of the task steps.

Created: 25 Oct 2012 | 4 comments


Using Altiris 7.1 Jobs and tasks, I have created a job that runs 3 tasks when the user logs on.

had to do it when the user logged on so no disruption to user.

1. Uninstalls an old program

2. Installs a new program

3. Creates a dir

Its quite quick but I dont want this to run at every logon.

Thought I could add a script that says if exist "filename" exit code 1

Dont seem to be able to get any other return code than 0.

I could perhaps do a findstr "string in old file"

Then if it finds the string it will return 0 and carry on the rest of the steps.

If the old software had already been uninstalled it wouldnt find the string and return 1

Is this a good way to go? Does anyone already do this and know a better way?


Comments 4 CommentsJump to latest comment

JimChud's picture

theres a few ways you can do this depending on the script language you are doing this in.

if its batch you can do things like below but you can also do if not exist for example.

You can then use the goto commands to move through the script sections. you can add in additional logging if you require for your script parts that would get you around the it running or copying every time atleast.

REM Remove NS Agent

if exist "C:\Program Files\Altiris\Altiris Agent\AexAgentUtil.exe" goto X86
if exist "C:\Program Files (x86)\Altiris\Altiris Agent\AexAgentUtil.exe" goto X64
goto EXIT

cd "\Program Files\Altiris\Altiris Agent\"
AexAgentUtil.exe /Clean /UninstallAgents
goto EXIT

cd "\Program Files (x86)\Altiris\Altiris Agent\"
AexAgentUtil.exe /Clean /UninstallAgents
goto EXIT

Echo Hello World

So you could do something like:

if exist "c:\Program Files\Application Folder\applicationfile.exe" (goto UninstallApp) ELSE (goto Step1)

start Wait MSIEXEC /X appmsifile.msi /qn
goto ApplicationCheck

Start Wait MSIEXEC /I NEWAPPFILE.msi /qn
goto Step2

if exist "c:\Program Files\New Application Folder\New Folder" goto exit
mkdir "c:\Program Files\New Application Folder\New Folder"


Regards Jim.
Connect Etiquette: "Mark as Solution" those posts which resolve your problem and give a thumbs up to useful comments, articles and downloads.

andykn101's picture

I'd use Managed Software Delivery for this.

Create a Software Resource for the old program with a Detection rule for it and an uninstall command line that is set as the default uninstall command.

Create an install batch file for the new program that installs it and creates the directory.

Create a Software Resource for the new program, include the batch file and make a install command line calling the program. Create a detection rule for the new program. Create an association so that the new program supersedes the old one.

Create a Managed Software Delivery for the new program by right clicking on the Software Resource > Actions > Managed Software Delivery. once it is created, make sure the Schedule is set to User Logon and select the "Automatically upgrade..." option.

Then the policy will run at every user logon check for the old software but only uninstall it if it finds it, and then check for the new software and only install it if it finds it.

You can also right click on the Software Resource for the new software and create a filter of all machines with it installed. You can then exclude that filter from the target of the policy.

Authorised Symantec Consultant (ASC) with Endpoint Management Limited, an Authorised Symantec Delivery Provider based in the UK.

Connect Etiquette: Please "Mark as Solution" posts that fix your problem.

stevericks's picture

Thanks Jim and Andy for the quick responses,

I thought of both the above ways, the trouble with the first way is that it is all in 1 batch script. I have 3 seperate tasks, each with their own script, the last one being a vbscript.

 The managed software delivery I did try, although I just added the install as the managed and the uninstall as a task, I might look at that again with adding the uninstall to the original package.

But it still leaves me the final task running every time. Again, it doesnt take long, so its not really a problem.

Just thought if i could add a task at the top of the job, like in a managed delivery, that did a detection rule, it would be a good idea.


stevericks's picture

Another point....On DS 6.9 I can do

IF EXIST "C:\Program Files\VideoLAN\VLC" exit 200

It will exit with a code of 200, if it exists.

I can then use the code to stop the job or continue.