Tuesday, June 30, 2009

In my previous post, I mentioned that using the Microsoft Visual Studio Setup and Deployment Wizard's Registry Editor to add in your custom application's path to the system path environment variable has an unfortunate side effect - the uninstaller will delete the system path variable.

A better but longer way is to write your own custom action program to add in your custom application's path to the system path environment variable during installation. In the custom action program (I call it AddPath and I use C# in my example code), I call a SetPathVariable function from main as shown below to do the job.

class Program

{

static void Main(string[] args)

{

try

{

//Call this function to add in my custom application's location to the system path variable

SetPathVariable();

}

catch

{

}

finally

{

}

}

The SetPathVariable will read in the AddPath program's command line arguments to find the custom application's location.

Monday, June 22, 2009

Microsoft Visual Studio.NET 2003/2008 has a setup and deployment wizard which you can use to create installers for your custom applications. During the installation of your application, you might want your installer to automatically add in the path to your custom application executable to the Windows system path.

The Visual Studio setup and deployment project has a Registry Editor which you can use to get your installer to add in your application registry keys and values. For instance, by using the Registry Editor, you can add in the registry keys under HKEY_LOCAL_MACHINE to set the Windows Path.

Underneath \\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment keys, you can add in a Environment StringPath value with the string "[%Path];[TARGETDIR]", as shown below.

Once that is done, your installer will automatically set the Windows environment Path variable to include the path to your custom application's executable.

But there is a problem with this method: when you uninstall your custom application, the uninstaller will remove the Path string from the Registry. A better approach would be to create a small Custom Action program to add modify the Registry instead. I will post details about that method later here.

Wednesday, June 3, 2009

If you have written any VB6 and earlier programs for running in the Windows Command prompt as batch programs, you would have noticed that control is returned back to you or your calling script almost immediately after execution. There is no convenient way to know when the program execution has completed before executing the next line in your calling script. Global Mapper is an example executable that exhibits the same behavior but it has its batch execution engine that lets you get around this issue.

I have written a C# wrapper program that will wrap around executables that behave like VB6 executables. The wrapper program essentially works like this:

Before starting up an instance of the executable, get a list of all running processes that have the same executable name.

Start up an instance of the executable.

Get a second list of all running processes that has the same executable name.

If the second list has a process id that is not in the first list, then that is my executable instance.

In a while loop, periodically check to see whether my executable instance is still running in the process list. If it is not in the running list, then exit from the loop and return to the calling method.