עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

בעיה בקריאת ערכים מהרג'יסטרי [#c]

Featured Replies

פורסם

אני מנסה לקרוא ערך מהרג'יסטרי, הערך קיים, אבל משום מה המתודה RegistryKey.getValue מחזירה לי null


RegistryKey oemInfo = Registry.LocalMachine;
oemInfo = oemInfo.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion");

//check if oemInformation key exists
if (oemInfo.OpenSubKey("OEMInformation") != null)
{
try
{
oemInfo = oemInfo.OpenSubKey("OEMInformation");
Console.WriteLine(oemInfo.GetValue("Manufacturer").ToString());
}
catch
{}
}

עד כמה שידוע לי הקוד נכון, רץ כמו שצריך וכו'.. כמובן שמתקבלת שגיאה ש oemInfo.GetValue("Manufacturer") הוא null, אבל אם אני עושה oemInfo.GetValue("Manufacturer", "no value") מה שאני מקבל הוא הסטרינג "no value"

*אני יודע בוודאות שהערך Manufacturer קיים, אני בעצמי יצרתי אותו ווידאתי שהוא לא נמחק בטעות...

לשם בדיקה ניסיתי את הדבר הבא:

string[] values = oemInfo.GetValueNames();
Console.WriteLine(values.Length);

ומשום מה גם הוא לא מזהה ערכים ומה שאני מקבל הוא 0. וכמובן ששוב ה"מחשב" טועה, כי אני יצרתי 6 ערכים במפתח המסויים הזה...

פורסם

היי אילן,

אתה חייב בעצם לבקש שוב את כל המפתח


oeminfo= Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation");

פורסם
  • מחבר

אתה מתכוון בתוך ה TRY? כי ניסיתי את זה, ואותה התוצאה...


RegistryKey oemInfo = Registry.LocalMachine;
oemInfo = oemInfo.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion");

//check if oemInformation key exists
if (oemInfo.OpenSubKey("OEMInformation") != null)
{
try
{
oemInfo = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation");

string[] values = oemInfo.GetValueNames();
Console.WriteLine(values.Length);
}
catch(Exception ex)
{
MessageBox.Show("Error loading OEM information from registry\n"+ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

אני עדיין מקבל 0...

פורסם

הקטע קוד שלך עובד אצלי As is.

לקחתי אותו ככה, הרצתי, החזיר null ו-0. בדקתי ברגיסטרי, אכן אפס.

יצרתי ערך חדש עם השם שנתת Manufacturer והרצתי את אותו קוד שוב, נתן את הערך וגם החזיר 1 באורך.

אולי יש לך שגיאה בשם של המפתח שאתה מחפש, אות גדולה/קטנה, משהו כזה? הקוד עצמו עובד פרפקט...

פורסם
  • מחבר

בדקתי הכל 20 פעם, עשיתי copy paste מהרגיסטרי... שום דבר...

מוזר :P

פורסם

אצלי זה עבד כמו שזה, כנראה שהבעיה היא באמת לא בקוד

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.