# Monday, April 28, 2003
You would think that compiling resources for .NET using resgen would be pretty straightforward, and most of the time you'd be right.
However, if you are trying to automate your build process by running resgen through some autmatic batch process (I happened to be using Draco) there's one little problem. If your resource file (.resx) happens to contain any embedded bitmaps or icons, the resgen compiler wants to turn them into real bitmaps during the compilation process.
Apparently, in order to do this, it really draws the bitmaps, and in doing so requires that there be a current desktop context into which to draw said bitmaps. If you run as a service (or in fact build using a batch file launched as a scheduled task) there isn't any desktop context. Resgen happily returns an exit code of 0, and fails to actually compile any resources. This took me a while to figure out as it was, but what to do about it is an even thornier problem. It turns out that when you call the underlying Win32 CreateProcess function, you can tweak the STARTUPINFO struct to set the desktop to something meaningful. Unfortunately, there's no way to get at that struct from managed code.
After contemplating changing the code in Draco in some nasty way, I finally discovered that if I ran my Draco.NET service as "Local System" and checked the box that says "Allow service to interact with the desktop" that the resource compilation would succeed. However, other bits of my build process failed because while running as local system I could no longer use SSPI authentication to my CVS repository, or copy files to network shares when the build finished.
Many triles and tribulations later (and some very strange network permissions here and there) it's now working again, but it took a good 7-8 person days to resolve the issue.
YUCK