Take the 2-minute tour ×

I am developing a c# .net 3.5 windows service on Windows 8 x64.

I need to see if a specific package id is under the node HKEY_CLASSES_ROOT\ActivatableClasses\Package.

This is the code

internal static bool IsPackageInstalled
                var packageKey = Registry.ClassesRoot.OpenSubKey(@"ActivatableClasses\Package");
                if (packageKey != null)
                    return packageKey.GetSubKeyNames().Any(key => key.StartsWith(MyPackageName, StringComparison.InvariantCultureIgnoreCase));
            catch (Exception ex)


            return false;

When running this code in a console application it works ok and returns true.

But when running the code within a Windows service, I am getting false. I tried to debug it and I saw that in a service the list of subkeys names contains only 2 keys, while there are actually 21 sub keys.

what could have caused this behavior?

UPDATE: The problem is that the service is running under a different user, and therefore every package that appears only under HKEY_CURRENT_USER won't appear when the service queries the registry.

Is there a way for the service to check another user registry (even if the user is not currently logged in)?

share|improve this question
Do you see the extra keys in HKEY_LOCAL_MACHINE\Software\Classes? HKEY_Classes_Root is a combination of local machine and user classes. –  Amiram Korach Nov 12 '12 at 14:43
What architecture is your application being compiled to? x86 or x64? –  Arran Nov 12 '12 at 14:45
These are Windows Store app keys, I'd definitely assume security preventing you from hacking them. Try it with a different user account for the service. –  Hans Passant Nov 12 '12 at 15:09

2 Answers 2

The HKEY_CLASSES_ROOT key is actually a virtual key that amalgamates two others keys:


It's most likely the values you want exist under the USER portions. Remember that services do not run under the context of a normal user like your console application.

For more information on the registry keys see here:


You can however set the service to run as a specific user which does have these values.

share|improve this answer

My assumption is that it has to do with permissions. Different areas of the registry have differing permissions. As a troubleshooting step i would try running my service as another user to see if the results change. If so, then you might want to look into impersonation.

share|improve this answer

Your Answer


