I want Policy Plus to be able to read policy settings from normal POL files, straight from the Registry, or both at once, so I need to have a common interface of some kind. Today I put together and partially implemented IPolicySource. It currently has two implementing classes: PolFile, which is mostly done, and RegistryPolicyProxy, which is all stubs at the moment.
PolFile can load POL files and determine whether a Registry value exists, including figuring out whether a value will be deleted by any of the several deletion commands. Since the Registry is case-insensitive, it lower-cases everything, but it also keeps track of the first original casing used for each path so that it can (eventually) write the values in their original style. That's so that people see pretty names if they open their Registry.
You can see the current code on GitHub.
Various technical articles, IT-related tutorials, software information, and development journals
Thursday, July 7, 2016
Wednesday, July 6, 2016
ntuser.pol: How Windows knows which Registry settings are from policies
The Policies subkey under HKLM or HKCU in the Registry is automatically updated when Group Policy is updated (either on the domain or on the local machine). It's also possible to add entries directly to those Registry locations. Settings added in that way won't show up in the Local Group Policy Editor, but they won't be removed in the next policy refresh. I found several mentions of Group Policy cache files, but they don't exist at all on non-domain-joined Pro machines.
Windows can't just rely on delete-value commands in Disabled policies because changing a set policy to Not Configured needs to remove the values too. To figure out how Windows knew to keep around manually-entered values, I used Process Monitor. Evidently, the Group Policy updating service compiles all applicable GPOs into one POL file called ntuser.pol. That file is stored in \ProgramData for the machine settings and in \ProgramData\Micorosft\GroupPolicy\Users\[SID] (*) for user settings. Whenever Group Policy is updated, the service compares the new settings against that file, then removes all Registry items that were set by policy but don't appear in the new version. Once the new settings are written, it rewrites ntuser.pol.
Windows can't just rely on delete-value commands in Disabled policies because changing a set policy to Not Configured needs to remove the values too. To figure out how Windows knew to keep around manually-entered values, I used Process Monitor. Evidently, the Group Policy updating service compiles all applicable GPOs into one POL file called ntuser.pol. That file is stored in \ProgramData for the machine settings and in \ProgramData\Micorosft\GroupPolicy\Users\[SID] (*) for user settings. Whenever Group Policy is updated, the service compares the new settings against that file, then removes all Registry items that were set by policy but don't appear in the new version. Once the new settings are written, it rewrites ntuser.pol.
*This was updated in 2025 for Windows 11. When this post was originally written, the file was in the root of each user's profile folder.
Tuesday, July 5, 2016
Policy Plus - Comment files
The Group Policy Editor lets you attach comments to policies. Those comments are stored in a file called comment.cmtx alongside the POL file. The CMTX format does not appear to be documented anywhere. Fortunately, it's fairly similar to the ADMX format. It's an XML file (with three unknown bytes tacked onto the beginning). It has a string table for some reason that I don't understand - it's stored in the same file as the policy list, obliterating the possibility of doing an ADML-style separation of objects and texts. There's also an ADMX-like prefix table, though CMTX files don't target any namespace.
The code to load CMTX files and produce a policy-to-text mapping is available on GitHub.
The code to load CMTX files and produce a policy-to-text mapping is available on GitHub.
Monday, July 4, 2016
What are those \??\ (backslash double question mark backslash) paths in Windows?
In certain places within Windows (usually the Registry), you'll see paths that begin with double question marks between backslashes, \??\. These are NT Object Manager object names. The Object Manager is a kernel-mode system that organizes various objects into a tree-like hierarchy. In other places, you may have seen path-like things that start with \Device\. Those are also Object Manager paths, and everything in the \??\ folder is actually a symbolic link to other places in the hierarchy. \??\C: links to the HarddiskVolumeN object for the volume holding your C drive, where N is a number. Only certain parts of Windows are designed to accept Object Manager paths, so you can't use them anywhere you would a normal path.
You can explore this hierarchy with the WinObj tool from Sysinternals.
Note that these paths are completely different than \\?\ paths, which are literal extended-length paths that you can use to access or create file system objects with weird characters in the name.
Based on my Super User answer.
You can explore this hierarchy with the WinObj tool from Sysinternals.
Note that these paths are completely different than \\?\ paths, which are literal extended-length paths that you can use to access or create file system objects with weird characters in the name.
Based on my Super User answer.
Sunday, July 3, 2016
Policy Plus - Object-orient all the things
Today I filled out the rest of Policy Plus's AdmxBundle.BuildStructures method. It now compiles all the raw ADMX structures into object-oriented classes with hierarchies and relationships. That includes categories, products, policies, and supported-on definitions.
While testing it, I discovered that a Windows ADMX file - PreviousVersions.admx - tries to reference a product from an ADMX file it hasn't imported, so I had to add some handling of that case to the ResolveRef function. If the source ADMX doesn't import a namespace it references, Policy Plus doesn't bother expanding the ref, which will probably always cause the target to not be found, so the supported-on entry that tried to refer to it will just not be added to the support definition.
Other than that, it worked perfectly. I can use Visual Studio's object inspector to look through the ADMX bundle to see the tree of categories and policies.
While testing it, I discovered that a Windows ADMX file - PreviousVersions.admx - tries to reference a product from an ADMX file it hasn't imported, so I had to add some handling of that case to the ResolveRef function. If the source ADMX doesn't import a namespace it references, Policy Plus doesn't bother expanding the ref, which will probably always cause the target to not be found, so the supported-on entry that tried to refer to it will just not be added to the support definition.
Other than that, it worked perfectly. I can use Visual Studio's object inspector to look through the ADMX bundle to see the tree of categories and policies.
Saturday, July 2, 2016
Office 2016 is apparently stable now
More than a year ago (wow), I tried a preview version of Office 2016. It did not go well. It did work on Windows 10, though, and I tried it a little in a VM. A few days ago on my Windows 8.1 main machine, Office 2013 asked me to update to the newest version of Office. I hesitantly accepted. It downloaded and installed the new programs successfully.
The only hiccup I ran into during setup was that the first post-upgrade run of each application put up the normal "didn't start correctly last time" dialog, but that went away on later runs. The only application I've been using heavily since the upgrade is Word, and it seems to be working fine. Evidently, Microsoft worked out the kinks.
Interestingly enough, PowerPoint always wants to run as administrator now. That's not happening with any other Office program. It still works fine once I elevate it, though.
The only hiccup I ran into during setup was that the first post-upgrade run of each application put up the normal "didn't start correctly last time" dialog, but that went away on later runs. The only application I've been using heavily since the upgrade is Word, and it seems to be working fine. Evidently, Microsoft worked out the kinks.
Interestingly enough, PowerPoint always wants to run as administrator now. That's not happening with any other Office program. It still works fine once I elevate it, though.
Friday, July 1, 2016
Policy Plus - Late loading
Yesterday, I wrote a little bit of code for Policy Plus that assembled the AdmxCategory structures into the more object-oriented PolicyPlusCategory structures. My implementation had a problem, though. If a new ADMX file was added after the call to LoadFolder, RawCategories would be empty and it wouldn't be able to resolve references to categories defined in ADMX files that were loaded earlier. So, I added a temporary dictionary and a function that searches both that and the existing categories. There's actually still a flaw in my most recent commit - the Categories dictionary doesn't contain child elements, so late-loaded categories can only reference existing top-level categories. That's fixed, but I have more changes I want to make (getting the other kinds of resources object-ified) before I push a new commit.
Subscribe to:
Posts (Atom)
