您的位置:首页 > 编程语言 > C#

验证本机的excel版本的C#代码

2018-10-12 14:07 357 查看

/// <summary>
/// 安装的excel的版本,0为没有安装,大于1说明安装了多个.
/// </summary>
/// <returns></returns>
public static List<string> ExcelVersion()
{
List<string> list = new List<string>();
List<string> lisemp = new List<string>();
List<string> listvison = new List<string>();
RegistryKey rk = Registry.LocalMachine;
RegistryKey akey = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office");
RegistryKey csk;
string str;
Hashtable hash = new Hashtable();
string[] ss = akey.GetSubKeyNames();
foreach (string s in ss)
{
string strem = @"SOFTWARE\\Microsoft\\Office" + @"\\" + s;
csk = rk.OpenSubKey(strem);
string[] csd = csk.GetSubKeyNames();
foreach (string sk in csd)
{
if (sk == "Excel")
{
str = strem + @"\\" + "Excel";
list.Add(str);
lisemp.Add(s);
}
}
}
if (list != null)
{
for (int index = 0; index < list.Count; index++)
{
list[index] = list[index] + @"\\InstallRoot\\";
RegistryKey f = rk.OpenSubKey(list[index]);
if (f != null)
{
listvison.Add(lisemp[index]);
}
}
}
return listvison;
}

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: