PDA

View Full Version : سوال: مشکل در وارد کردن مقادیر به registry .



i.zeid
جمعه 08 شهریور 1392, 03:55 صبح
دوستان عزیز خسته نباشید .

من یک برنامه دارم می نویسم که یک سری از مقادیر registry رو تغییر می ده . خوب این کار خیلی ساده است و خود C#‎‎‎‎‎ توابع بسیار خوبی داره برای این کار ولی به یک مشکل جالب برخوردم و امیدوارم یکی از دوستان کمک کنه :

اولین مشکلم اینه که اصلا چطوری یک string hex رو می تونم وارد registry کنم ( نمونه کد اینجاست ) :


[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


منظورم از hex مقداری هست که برای پسورد قرار داده شده در کد بالا.

دوم اینکه ... من سعی کردم با استفاده از CMD مقادیر registry رو تغییر بدم با کد زیر :

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\ESET\ESET Security\CurrentVersion\Plugins\01000400\Profiles\ @My profile" /v Username /d test /f

خیلی عالی و بی نقص کار کرد. ولی وقتی همین رو با استفاده از کد C#‎‎‎‎‎ نوشتم حتی با دسترسی ادمین هم نتونستم نتیجه بگیرم .. پیغامی که به من داده شد این بود که همه چیز با موفقیت انجام شده .. ولی هیچ تغییری در registry ندیدم.
کدی که استفاده کردم اینه :




strCmdText = "REG ADD \"HKEY_LOCAL_MACHINE\\SOFTWARE\\ESET\\ESET Security\\CurrentVersion\\Plugins\\01000400\\Profi les\\@My profile\" /v Username /d testfrom /f";
// System.Diagnostics.Process.Start("CMD.exe", strCmdText);
string res = GETCMD(strCmdText);

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;
}



به هیچ عنوان نتیجه نمی گیرم .. لطفا اگر کسی می تونه کمک کنه

group45
جمعه 08 شهریور 1392, 06:14 صبح
سلام
کد زیر مشکلتون رو حل میکنه قطعا.روی فالس دقت شود.

RegistryKey rk = Registry.LocalMachine.OpenSubKey(t_path , false);