Search code examples
c#.net-3.5compact-frameworkpinvokewindows-ce

How can I incorporate an AddReg section into a config file for a Compact Framework app?


I'm trying to update a registry value in a Windows CE / Compact Framework app.

I can do what I want in .NET 4.5, but .NET 3.5 is missing some of the pieces to do it that way (specifically RegistryView and OpenBaseKey; the curious can peruse all the gory details here).

Another possibility is to ship a *.reg file with the app and invoke it via ShellExecuteEx(), but that seems a bit Rubegoldbergish to me.

Yet another possibility is to use P/Invoke, but that seems like modified Hobbesianism (nasty and brutish, but not short (short would be good in this case)).

SO...I did finally find something that seems like an almost eurekaphoric option. According to Andy Wigly in his book "Microsoft .NET Compact Framework" (printed 1879 or so), you can add or manipulate registry values via a configuration file. This config file seems to be embedded in a/the cab when the app is deployed on the device. Quoting from the book:

"*AddReg *
Defines the name of the section of the configuration file for adding entries to the registry; ..." (p. 211)

-and:

"*Description of the AddReg Section*
The *AddReg* sections are optional sections of the configuration file. These sections are defined by the *AddReg* key under the *DefaultInstall* section of the configuration file. Each section defines the registry keys, and values are added to the registry when your application is installed. For more information, see the device's SDK (p. 213)

But what configuration file is here being so cavalierly bandied about? I can't locate where he backs up and gives fundamental info about it.

Okay, I can try to locate "the device's SDK" (they are Motorola 3090/3190 devices onto which this app is installed) but am hoping that somebody knows just which configuration file he's talking about, and what the needed entry looks like.

We have a separate install app for this app, and I searched it for "AddReg" and "DefaultInstall", but to no avail.

I'm thinking that the file probably has to have a specific name for the cab to know what it is and run it (*.config?) and that the entry might be something like:

[DefaultInstall]
[AddReg]
"GuestOnly"="00000001"

...but I don't really know, that's just a guess. Does anybody know what this entry is supposed to look like? It sure would be a much simpler way of changing the registry val than P/Invoke and the like.

It's not the *.vcproj file, is it? (the setup app is written in C++; the app itself is C#).

UPDATE

It turns out I may be barking up the wrong tree with this attempt to update the "GuestOnly" setting.

UPDATE 2

At any rate, it can't hurt (and may help) to updated that value; so, I looked through our C++ install app, but it contains no .inf files, nor any reference to such, so I guess the best or only real way to do this is by adding the registry updating code to the app itself. I call it from the main form's Load() event.


Solution

  • Many ways to skin that cat, but I typically have that kind of thing right in the CAB setup. I use a program that slaps a UI on it, but all it is doing is creating a configuration file (.inf) and passes it to CAB Wizard (https://msdn.microsoft.com/en-us/library/aa448616.aspx).

    The file info, including AddReg is here (https://msdn.microsoft.com/en-us/library/aa448654.aspx).