Hello,
We don't have predefined support to search if an environment variable exists or not.
In this case, you can create a sample custom action that performs this search. For example, you can use the
Environment.GetEnvironmentVariable Method (String) to retrieve the value of an environment variable.
Also, please take a look on the
How to integrate and debug custom actions? article which may be useful to you.
A sample code that performs this check is the following:
Code: Select all
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
using System.Windows.Forms;
namespace Check_EnvironmentVariable_existance
{
public class CustomActions
{
[CustomAction]
public static ActionResult CheckEnviromentVariable(Session session)
{
session.Log("Begin CheckEnviromentVariable");
// Check whether the environment variable exists.
string envirVar = Environment.GetEnvironmentVariable("EnvirNameTest");
// the environment variable does not exist
if (envirVar == null)
{
session.Log("The environment variable does not exist");
MessageBox.Show("The EnvirName does no exist. The installation will stop!");
return ActionResult.Failure;
}
else
{
return ActionResult.Success;
}
}
}
}
You can also use a
script powershell in order to check if the environment variable exists. For the powershell code approach, you can use the
Run Windows PowerShell Script custom action.
The sample project is attached to this thread, so if you are interested to take a look directly at my project, you are more than welcome to download the ZIP file.
Should there be any difficulty you encounter implementing something, please do not hesitate to contact me and I will gladly assist.
Best regards,
Dan
FOLLOW US
Get the latest news in Application Packaging