Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

NVM - eNvironment Variables Manager

3.91/5 (10 votes)
14 Oct 2007CPOL3 min read 1   510  
NVM is a easy-to-use tool written in C# 3.0. The aim of this tool is to allow easy administration of Windows Environment Variables.

Screenshot - NVM_Main.jpg

Introduction

Hi, this is my first article in CodeProject. Not long ago, I was introduced to the world of .NET and the C# programming language, and I liked it very much. Moreover, being a regular visitor of CodeProject, this site helped me strengthen my skills in C#. This tool, NVM, provides me a chance to give something back to the developer community.

Editing and manipulating environment variables is a very cumbersome and non-user-friendly procedure under Windows. NVM aims at making Environment variable administration a simple and user-friendly procedure. It also provides more features than the basic environment variables editor provided by Windows.

Background

I would like to thank Jonathan [Darka] for his SetEnv article and Vladislav Setchin for his EnvMan article which provide great insight on manipulating environment variables through code. I have extended their ideas (but not their code!). This tool is written from scratch, and it gave me an in-depth view of programming with the DataGridView. I would also like to thank Michael Bright for his great article Registry's Ins and Outs using C# which describes in detail about manipulating the Registry through C#.

Using the program

I built this application using Microsoft Visual Studio 2008 Beta 2 (Orcas), so in order to execute the application, you need to have .NET 3.0 or the .NET 3.5 runtime installed.

Using the code

In the Registry, the User environment variables are stored at:

HKEY_CURRENT_USER\Environment

and the System environment variables are stored at:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment

So, you can either use the System.Environment class and its GetEnvironmentVariables, GetEnvironmentVariable, SetEnvironmentVariable functions to obtain or set the values, respectively, or you can use the Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey classes to directly access the Registry.

Once the value is obtained, it is split into tokens based on the separator character ";", and these tokens are displayed in the grid for easy manipulation.

Screenshot - NVM_Details.jpg

The Export feature allows the user to export the user environment variables and the system environment variables to an XML file.

Updates

I have updated the application and released the source code and binary. The following updates have been incorporated:

  • A bug related to the New button of the second form has been resolved.
  • A Browse For Folder button has been added to the second form. Using this, the user can browse for any folder of his/her choice, and once a folder is selected, its path is added to the Clipboard. This can be used to paste while editing or adding a new value.
  • The main form and the second form are now sizable. You can resize the forms to your own requirements.
  • The font size has been reduced from size 10 to size 8 to accommodate more data.

Future Features

I am planning to incorporate the following features in the future versions:

  • Add an Import feature to complement the Export feature.
  • Add progress bar support while saving to the Registry. As of now, the application hangs for sometime while saving to the Registry. I am looking into this issue. (If anyone has any ideas on how to incorporate this, their suggestions are heartily welcome :) )
  • Apart from this, if anyone has suggestions for any other features that can be added, do let me know.

    Feel free to use the source code and add your modifications. I would appreciate it if you mention my name in the modified code.

History

  • 14-Oct-2007: Released NVM (version 0.9.x) binary and source code.
  • 07-Oct-2007: Released the NVM binary.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)