gpt4 book ai didi

c# - 知道是否为 "All users"安装了应用程序

转载 作者:行者123 更新时间:2023-12-03 20:44:10 25 4
gpt4 key购买 nike

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

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

有没有更好的办法?

最佳答案

扩展 Sachin Gaur 的回答:

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

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

参见 MSDN对于用于访问注册表的 GetValue 方法。

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

关于c# - 知道是否为 "All users"安装了应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/502717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com