tags:

views:

89

answers:

2

How do detect if my app was installed for "All users" or just for one user.

Today I check for files put in either Environment.SpecialFolder.CommonApplicationData or Environment.SpecialFolder.ApplicationData by my installer.

Is there a better way?

+1  A: 

I hope, this may be helpfull for you.
You can know whether application is installed for all user or not by reading the registry value. For this, you must know the product code of the application:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\

To read the registry entry in C#, you can use GetValue() method of Registry class in Microsoft.Win32.

Sachin Gaur
+1  A: 

To expand on Sachin Gaur's answer:

The S-1-5-18 folder is for Local System user - which is used when installing for All Users. Intallation for the current user would have the product key in a folder named after that user's security identifier (S-something-else).

To get the current user's SID, use System.Security.Principal.WindowsIdentity.GetCurrent() to get a WindowsIdentity. Then, use the User property to get a SecurityIdentifier. Then use ToString() to get the string value.

See MSDN for the GetValue method used to access the registry.

configurator