如何在安装部署项目中的install\uninstall中删除注册表项值

Chobohoo 2016-08-24 11:17:37
在public override void install\Uninstall(IDictionary savedState)中

可以新建注册表项,但删除的时候缺发现删除不了.

在一直找不到思路的情况下,我直接生成了一个.bat文件,用户删除注册表.
然后通过Process来打开这个.bat文件. 但同样都是删除不了.


还望各位大侠指点下..感谢..

下面是部分code:↓



System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
//判断当前登录用户是否为管理员
if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
{
string logFileName = @"c:\aa\cmd.bat";
//string logFileName = Path.Combine(base.Context.Parameters["targetdir"].Replace(@"\\", @"\"), "cmd.bat");
if (!File.Exists(logFileName))
File.Create(logFileName).Close();

StreamWriter sw = new StreamWriter(logFileName);
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"reg delete HKEY_LOCAL_MACHINE\SOFTWARE\test /v BatchJob_InputPath_T0 /f");
sb.AppendLine(@"reg delete HKEY_LOCAL_MACHINE\SOFTWARE\test /v BatchJob_InputPath_T3 /f");
sb.AppendLine(@"reg delete HKEY_LOCAL_MACHINE\SOFTWARE\test /v BatchJob_InputPath_T5 /f");
sb.AppendLine(@"reg delete HKEY_LOCAL_MACHINE\SOFTWARE\test /v BatchJob_InputPath_AccountCode /f");

sw.Write(sb.ToString());
sw.Close();

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = Path.GetDirectoryName(logFileName);
startInfo.FileName = Path.GetFileName(logFileName);
//startInfo.Arguments = "/c C:\\Windows\\System32\\cmd.exe";
startInfo.UseShellExecute = true;
startInfo.Verb = "RunAs";
startInfo.CreateNoWindow = false;

Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();

}
else
{
Console.Write("123123");
Console.ReadLine();
}

...全文
188 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Chobohoo 2016-08-24
  • 打赏
  • 举报
回复
困扰了好几天的问题了...

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧