September 12th, 2018

How do I get the system to run my program in this very special way?

A customer registered their program to be run automatically under conditions not important to the story. They found, however, that the program didn’t work because the program was written with an application framework that looks for configuration files in the current directory, but the system wasn’t setting the current directory properly. They couldn’t change the directory in their program because the code that looks for the configuration file is in the framework, and it runs before any of their code does.

Oh, and I forgot to mention that mention that the FIZZBIN environment variable needs to be set to KRONK, except on Tuesdays, in which case it needs to be SHRONK. Except at night.

Okay, maybe the customer’s requirements weren’t that weird, but you get the idea.

You can’t get the system to do all these things for you, but you don’t have to.

Write a helper program and register the helper with the system. The helper program sets the current directory, sets the FIZZBIN environment variable, does all the fancy preliminary nonsense your precious program requires, and then launches the real program.

Bingo, your current directory, environment variable, and favorite teddy bear are all set up waiting for you.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.

Feedback