听到我有一个十六进制值,我不知道这个原始值是什么:
[HKEY_LOCAL_MACHINE\SOFTWARE\ESET\ESET Security\CurrentVersion\Plugins\01000400\Profiles\@My profile]
"Username"="test"
"Password"=hex:50,d6,e6,e9,ee,f0,cf,f2,6e,64,03,ad
我想将这些值添加到注册表中,我尝试使用命令提示和管理员权限,并使用以下命令获取用户名:
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\ESET\ESET Security\CurrentVersion\Plugins\01000400\Profiles\@My profile /v Username /d test /f
它就像一个魅力。然后我将以下行添加到VS2010中的app.manifest文件中:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
为了获得管理权限,我使用了以下在此站点中找到的命令:
private string GETCMD(string com)
{
string tempGETCMD = null;
Process CMDprocess = new Process();
System.Diagnostics.ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo();
StartInfo.FileName = "cmd"; //starts cmd window
StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
StartInfo.CreateNoWindow = true;
StartInfo.RedirectStandardInput = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.UseShellExecute = false; //required to redirect
CMDprocess.StartInfo = StartInfo;
CMDprocess.Start();
System.IO.StreamReader SR = CMDprocess.StandardOutput;
System.IO.StreamWriter SW = CMDprocess.StandardInput;
SW.WriteLine(com);
//insert your other commands here
SW.WriteLine("exit"); //exits command prompt window
tempGETCMD = SR.ReadToEnd(); //returns results of the command window
SW.Close();
SR.Close();
return tempGETCMD;
}
返回“操作已成功完成”但注册表中没有任何更改
我尝试使用c#函数直接将值设置为注册表,但它不起作用。
这是错的吗? 我如何将这些值设置为注册表? 为什么当我手动键入命令而不是程序化时,它是通过命令提示符工作,即使程序是以管理员身份启动的?已编辑:
我试过这个命令:
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\ESET\ESET Security\CurrentVersion\Plugins\01000400\Profiles\@My profile /v Username /d test /f
甚至这个
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\ESET\ESET Security\CurrentVersion\Plugins\01000400\Profiles\@My profile" /v Username /d test /f
我不知道用什么密码女巫用十六进制。
已编辑:
我尝试使用.reg文件听取内容:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ESET\ESET Security\CurrentVersion\Plugins\01000400\Profiles\@My profile]
"Username"="test"
"Password"=hex:50,d6,e6,e9,ee,f0,cf,f2,6e,64,03,ad
并且我使用以下代码来执行它,但即使使用管理员权限它也不起作用:
if (!String.IsNullOrEmpty(res))
{
string path = Path.GetTempPath() + "ajdm4SjhCHGS44AhhdJ892.reg";
File.WriteAllText(path, res);
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "regedit.exe";
// start.Arguments = " -s " + path;
start.Arguments = " " + path;
Process proc = Process.Start(start);
MessageBox.Show("Done!");
}
它始终显示操作已成功完成。但我不会更改注册表值。