Code:
using Microsoft.Win32;
using System;
using System.Drawing;
using System.IO;
namespace cyfang
{
public sealed class OEM
{
private RegistryKey _key
{
get
{
return RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32)
.OpenSubKey(KEY_PATH, true);
}
}
private const String KEY_PATH = @"SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation";
private const String LOGO_PATH = @"C:\Windows\logo.bmp";
public readonly String[] KEYS = { "Manufacturer", "Model", "SupportURL", "SupportHours", "SupportPhone", "Logo" };
public void CopyImageToSystemFolder(ref String path)
{
if (File.Exists(OEM.LOGO_PATH) == false)
{
var image = new Bitmap(path);
image.Save(OEM.LOGO_PATH);
image = null;
}
else
File.Copy(path, OEM.LOGO_PATH, true);
path = OEM.LOGO_PATH;
}
public String[] GetInfos()
{
int length = KEYS.Length;
String[] infos = new String[length];
for (int index = 0; index < length; index++)
infos[index] = _key.GetValue(KEYS[index], "").ToString();
return infos;
}
public void DeleteInfo(String key)
{
_key.DeleteValue(key);
}
public void DeleteAllInfo()
{
foreach (String k in KEYS)
_key.DeleteValue(k);
}
public void AddInfo(String[] newInfos)
{
for (int index = 0; index < newInfos.Length; index++)
_key.SetValue(KEYS[index], newInfos[index]);
}
}
}
執行結果:
