执行CMD命令C#(操作成功但不执行任何操作)

时间:2015-09-04 13:49:18

标签: c# windows batch-file cmd registry

System.Diagnostics.Process process = new System.Diagnostics.Process();

System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = @"/K reg add ""HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer"" /V IconUnderline /T REG_DWORD /D 1 /F";

process.StartInfo = startInfo;
process.Start();

如果我使用管理员权限运行该程序,它会说:

  

操作成功完成

问题是注册表项保持不变。

我做错了什么?我试图运行.bat,它有同样的问题。没有错误,它只是不修改注册表项。如果我在CMD中运行.bat或命令,它可以工作。如果我尝试从程序运行CMD命令或.bat文件(包含命令),它只是说“操作已成功完成”。什么都不做提前谢谢。

使用注册表类(无结果):

        RegistryKey RegKey1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer", true);
        RegKey1.SetValue("IconUnderline", 1, RegistryValueKind.DWord);
        RegKey1.Close();

0 个答案:

没有答案
相关问题