Question: I am creating a Visual Studio 2008 Setup Wizard for my program  

<http://support.microsoft.com/kb/307353>  

I see that it is possible to add registry entries, etc..
Is there a possibility to register windows environment variable without writing a custom action?  

And if I must write a custom action, what is the least painful way to do so?

Answer: 
Windows Installer does support environment variables through [Environment](http://msdn.microsoft.com/en-us/library/windows/desktop/aa368369%28v=vs.85%29.aspx) table, but Visual Studio setup projects do not allow you to use it.

A solution is to use a different setup authoring tool which supports environment variables: <http://en.wikipedia.org/wiki/List_of_installation_software>

Another solution is to manually add it in Environment table by editing the MSI with [Orca](http://msdn.microsoft.com/en-us/library/windows/desktop/aa370557%28v=vs.85%29.aspx).

There's also the custom action approach you mentioned.
Ickydime (see answers above) custom action sample shows how to add an environment variable by expanding the PATH env variable. I'm sharing below how to create a new environment variable using `Environment.SetEnvironmentVariable`

```
    string environmentKey = "MY_VAR";
    string pathUrl = "%ProgramFiles%\\...";
    public Installer1()
    {
        InitializeComponent();
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Commit(IDictionary savedState)
    {
        base.Commit(savedState);
        Environment.SetEnvironmentVariable(environmentKey, pathUrl, EnvironmentVariableTarget.Machine);
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Rollback(IDictionary savedState)
    {
        base.Rollback(savedState);
    }

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
        Environment.SetEnvironmentVariable(environmentKey, null, EnvironmentVariableTarget.Machine);
    }

```