知道是否为“所有用户”安装了应用程序

Nif*_*fle 3 .net c#

如何检测我的应用是为“所有用户”安装的还是仅为一位用户安装的。

今天,我检查安装程序中的文件Environment.SpecialFolder.CommonApplicationDataEnvironment.SpecialFolder.ApplicationData由我的安装程序放置的文件。

有没有更好的办法?

con*_*tor 5

扩展 Sachin Gaur 的回答:

S-1-5-18 (*)文件夹用于本地系统用户 - 在为所有用户安装时使用。当前用户的安装会将产品密钥放在以该用户的安全标识符 (S-something-else) 命名的文件夹中。

要获取当前用户的 SID,请使用System.Security.Principal.WindowsIdentity.GetCurrent()来获取WindowsIdentity. 然后,使用该User属性获取SecurityIdentifier. 然后用于ToString()获取字符串值。

有关用于访问注册表的 GetValue 方法,请参阅MSDN

(*) HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\