确定用户安装的应用程序 [英] Identify the applications installed by User

查看:96
本文介绍了确定用户安装的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我可以使用下面的代码获取机器上所有已安装应用程序的列表。如何识别用户安装的应用程序?

Hi,

I'm able to get the list of all installed applications on machine using below code. How can I identify application which were install by user?

 private void LoadSoftwareList() 
    { 
        listBox1.Items.Clear(); 
        ManagementObjectCollection moReturn;   
        ManagementObjectSearcher moSearch; 
 
        moSearch = new ManagementObjectSearcher("Select * from Win32_Product"); 
 
        moReturn = moSearch.Get(); 
       foreach(ManagementObject mo in moReturn) 
       { 
           listBox1.Items.Add(mo["Name"].ToString()); 
       } 
 
    } 

请建议。

谢谢。

推荐答案

你好Sham Dev eloper,

从以下文件中我们知道我们不能从Win32_Product中检索相关的安装用户信息。我们也无法通过注册表找到相关的用户信息。

From the following document, we know that we could not retrieve related install user information from Win32_Product. we also could not find related user information via registry.

https: //msdn.microsoft.com/en-us/library/aa394378(v=vs.85).aspx

我们只能检查是否安装了应用程序"所有用户"或" "特殊用户",有关详细信息,请参阅:

we could only Check if app is installed for "All users" or "Special User", For more information, please refer to:

 


//The S-1-5-18  =
Local System user (Everyone) | HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\

    //The S-XXXXXX  =
Current user (Just me)       |
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-?!?!?!?!\Products\

    string key;
    string keyFormat = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\{0}\Products\";
 
    // Check if installed for -> Everyone
    key = string.Format(keyFormat, "S-1-5-18");

using (RegistryKey regkey = Registry.LocalMachine.OpenSubKey(p_regKey))
    {
        if (regkey != null)
        {
            RegistryKey rk;
            string[] arrProducs = regkey.GetSubKeyNames();
            for (int i = 0; i < arrProducs.Length; i++) 
            {
               using (rk = regkey.OpenSubKey(arrProducs[i] + @"\InstallProperties"))
               {
if (rk != null &&
                        listBox1.Items.Add(rk.GetValue("DisplayName").ToString())               }
            }
        }
    }
     
    // Check if installed for -> Special User   
 key = string.Format(keyFormat, WindowsIdentity.GetCurrent().User.Value);
     //same as above.
    }

祝你好运,

张龙


这篇关于确定用户安装的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆