自动化测试之自动卸载软件

发表于:2014-2-14 11:46

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:肖佳    来源:51Testing软件测试网采编

  C#中卸载程序
  C#的卸载代码比较简单, 当然你也可以用其他语言。
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = "/x {C56BBAC8-0DD2-4CE4-86E0-F2BDEABDD0CF} /quiet /norestart";
p.Start();
  C#查找注册表中的ProductCode
  最麻烦的在于,如何到注册表中获取ProductCode。 如果做非Web程序的自动化测试,经常需要跟注册表打交道。
  代码为:
public static string GetProductCode(string displayName)
{
string productCode = string.Empty;
// 如果是32位操作系统,(或者系统是64位,程序也是64位)
string bit32 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
// 如果操作系统是64位并且程序是32位的
string bit64 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey localMachine = Registry.LocalMachine;
RegistryKey Uninstall = localMachine.OpenSubKey(bit32, true);
foreach (string subkey in Uninstall.GetSubKeyNames())
{
RegistryKey productcode = Uninstall.OpenSubKey(subkey);
try
{
string displayname = productcode.GetValue("DisplayName").ToString();
if (displayname == displayName)
{
string uninstallString = productcode.GetValue("UninstallString").ToString();
string[] strs = uninstallString.Split(new char[2] { '{', '}' });
productCode = strs[1];
return productCode;
}
}
catch { }
}
return productCode;
}
22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号