我尝试在本地计算机上安装已安装的软件以及带有时间戳的已安装日期。 但我只使用属性InstallDate得到像“20140225”这样的日期,我们还有一个属性InstallDate2,但我得到了null值。我想在c#.net中安装带有日期和时间的已安装程序。
任何人都可以为此提供解决方案。
提前致谢。
我的代码使用Registry:
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
// we have many attributes other than these which are useful.
Console.WriteLine(sk.GetValue("DisplayName") + "- " + sk.GetValue("DisplayVersion") + " -" + sk.GetValue("InstallDate") + " -" + sk.GetValue("Publisher"));
}
}
}
Console.ReadLine();
这是使用WMI代码:
ManagementObjectCollection moReturn;
ManagementObjectSearcher moSearch;
moSearch = new ManagementObjectSearcher("Select * from Win32_Product");
moReturn = moSearch.Get();
foreach (ManagementObject mo in moReturn)
{
Library.WriteLogMessageList("Name: " + mo["Name"].ToString() + "Date:" + mo["InstallDate"].ToString() + "Caption: " + mo["Caption"].ToString() + "Description: " + mo["Description"].ToString());
listPro.Add(new ListProgramProperties { Name = mo["Name"].ToString(), Caption = mo["Caption"].ToString(), Description = mo["Description"].ToString(), InstalledDate = mo["InstallDate"].ToString() });
// Console.WriteLine(mo["Name"].ToString()); //+ " || " +mo["InstallDate2"].ToString()
}
}
答案 0 :(得分:0)
这可能就是你所需要的:
替换
mo["InstallDate"].ToString()
与mo["InstallDate"].ToString("yyyy-MM-dd h:mm tt")
您可以在ToString()