本文整理汇总了C#中Microsoft.Win32.RegistryKey.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryKey.ToString方法的具体用法?C# RegistryKey.ToString怎么用?C# RegistryKey.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.RegistryKey
的用法示例。
在下文中一共展示了RegistryKey.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateKey
/// <summary>
///
/// </summary>
/// <param name="root"></param>
/// <param name="subKey"></param>
internal static void CreateKey(RegistryKey root, string subKey)
{
RegistryKey rk = null;
try {
rk = root.CreateSubKey( subKey );
if ( rk != null ) {
Log.AppendString( logfile, "Created key: " + rk.ToString() + Environment.NewLine );
Display.UpdateStatus( "Created: " + root.ToString() + "\\..." + subKey.Substring( subKey.LastIndexOf( '\\' ) ) + "\\*" );
}
}
catch ( Exception ex ) {
// Record exceptions in the log file
Log.AppendException( logfile, ex );
}
finally {
// Finally, cleanup and prepare variables for garbage collection
if ( rk != null ) {
rk.Close();
rk = null;
}
subKey = null;
}
}
示例2: SearchRegistryKey
/// 搜索注册表指定项
/// <param name="key">注册表项</param>
private void SearchRegistryKey(RegistryKey key)
{
if (key == null) return; //判断项是否为空
//获取注册表项的键名列表
string[] valueNames = key.GetValueNames();
//将注册表项加入到搜索状态提示中
SetSearchState(key.ToString());
//遍历所有键名,判断键名或键值中是否含有搜索的关键字
foreach (string valueName in valueNames)
{
//搜索的关键字
string keywords = tBKeywords.Text;
//获取键值并转换成字符串类型
string value = key.GetValue(valueName).ToString();
//判断键名或键值中是否含有搜索的关键字
if (valueName.Contains(keywords)
|| value.Contains(keywords))
{//如果含有搜索关键字
//将该键在注册表中的全路径添加到搜索结果列表中
AddSearchState(key.ToString() + "\\" + valueName);
}
}
//获取项的所有子项名
string[] subKeyNames = key.GetSubKeyNames();
//遍历所有子项,并对其进行搜索
foreach (string subKeyName in subKeyNames)
{
try
{
//根据子项名获取子项
RegistryKey subKey = key.OpenSubKey(subKeyName);
//如果子项为空,则继续搜索下一子项
if (subKey == null) continue;
//搜索子项
SearchRegistryKey(subKey);
}
catch (Exception)
{
//如果由于权限问题无法访问子项,则继续搜索下一子项
continue;
}
}
key.Close();
}
示例3: OpenDBConnection
public static OleDbConnection OpenDBConnection(RegistryKey regkey)
{
if (regkey==null)
return null;
OleDbConnection ret = null;
string connectionString = string.Empty;
string tmpStr = regkey.GetValue("Server") as string;;
if (tmpStr == null)
{
MessageBox.Show ("Не определена группа ключей "+regkey.ToString()+"Server");
return ret;
}
try
{
if (tmpStr.Length>0)
{ // указан сервер, значит БД SQL
connectionString =
"Provider=SQLOLEDB; Server="+tmpStr+";"
+ "database="+regkey.GetValue("DBName").ToString()+";"
+ "Integrated Security=SSPI; Persist Security Info=false;";
}
else
{ // не указан сервер, значит БД Access
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"+
"Data Source="+regkey.GetValue("DBName").ToString()+";";
}
}
catch{}
ret = new OleDbConnection(connectionString);
try
{
ret.Open();
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
ret = null;
}
return ret;
}
示例4: EnumMRUList
private void EnumMRUList(RegistryKey regKey, string subkey = "")
{
foreach (string strValueName in regKey.GetValueNames())
{
ProgressWorker.I.EnQ(string.Format("Scanning {0}\\{1}", regKey.ToString(), string.Empty));
string filePath, fileArgs;
// Ignore MRUListEx and others
if (!Regex.IsMatch(strValueName, "[0-9]"))
continue;
string fileName = ExtractUnicodeStringFromBinary(regKey.GetValue(strValueName));
string shortcutPath = string.Format("{0}\\{1}.lnk", Environment.GetFolderPath(Environment.SpecialFolder.Recent), fileName);
// See if file exists in Recent Docs folder
if (!string.IsNullOrEmpty(fileName))
{
//ScanDlg.StoreInvalidKey(Strings.InvalidRegKey, regKey.ToString(), strValueName);
this.BadKeys.Add(new InvalidKeys()
{
Root = Registry.CurrentUser,
Subkey = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RecentDocs",
Key = subkey != string.Empty ? subkey : string.Empty,
Name = strValueName
});
continue;
}
if (!File.Exists(shortcutPath) || !FileOperations.I.ResolveShortcut(shortcutPath, out filePath, out fileArgs))
{
//ScanDlg.StoreInvalidKey(Strings.InvalidFile, regKey.ToString(), strValueName);
this.BadKeys.Add(new InvalidKeys()
{
Root = Registry.CurrentUser,
Subkey = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RecentDocs",
Key = subkey != string.Empty ? subkey : string.Empty,
Name = strValueName
});
continue;
}
}
}
示例5: RecurseCopyKey
void RecurseCopyKey(RegistryKey sourceKey, RegistryKey destinationKey)
{
Logger.LogInfo(String.Format("Copying from {0} to {1}", sourceKey.ToString(), destinationKey.ToString()));
//copy all the values
foreach (string valueName in sourceKey.GetValueNames())
{
// Don't overwrite
if (!ShouldExcludeKey(valueName) &&
destinationKey.GetValue(valueName) == null)
{
object objValue = sourceKey.GetValue(valueName);
RegistryValueKind valKind = sourceKey.GetValueKind(valueName);
destinationKey.SetValue(valueName, objValue, valKind);
}
else
{
Logger.LogInfo(String.Format("Skipping value {0} as it already exists in the destination key", valueName));
}
}
//For Each subKey
//Create a new subKey in destinationKey
//Call myself
foreach (string sourceSubKeyName in sourceKey.GetSubKeyNames())
{
using (RegistryKey sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName))
{
using (RegistryKey destSubKey = destinationKey.CreateSubKey(sourceSubKeyName))
{
RecurseCopyKey(sourceSubKey, destSubKey);
}
}
}
}
示例6: ReadFromKey
private bool ReadFromKey(RegistryKey root)
{
System.Diagnostics.Debug.Assert(m_keyString != null, "m_keyString was not set prior to reading from key");
System.Diagnostics.Debug.Assert(root.ToString().EndsWith(m_keyString), "m_keyString did not match root registry key suffix");
try
{
string serverName = root.GetValue("Server", "").ToString();
int port = (int)root.GetValue("Port", 0);
string context = root.GetValue("Context", "").ToString();
string userName = root.GetValue("User", "").ToString();
string password = root.GetValue("Password", "").ToString();
root.Close();
Policy.Crypto crypt = Workshare.Policy.Crypto.Instance;
if (!string.IsNullOrEmpty(userName))
{
userName = crypt.DecryptData(userName);
}
if (!string.IsNullOrEmpty(password))
{
password = crypt.DecryptData(password);
}
ServerName = serverName;
Port = port;
Context = context;
UserName = userName;
Password = password;
}
catch (SecurityException e)
{
Logger.LogError(@"Cannot access the registry key [" + root + "]. ");
Logger.LogError(e);
return false;
}
catch (UnauthorizedAccessException e)
{
Logger.LogError(@"Cannot access the registry key [" + root + "]. ");
Logger.LogError(e);
return false;
}
catch (SystemException e)
{
Logger.LogError(@"Failed to read the settings from the registry key [" + root + "].");
Logger.LogError(e);
return false;
}
return true;
}
示例7: getRegistryConfSafe
public static object getRegistryConfSafe(RegistryKey key, String valueName, Object defaultValue, RegistryValueKind kind, bool create)
{
object retVal;
try
{
retVal = key.GetValue(valueName);
}
catch (Exception e)
{
try
{
if (create)
{
Logger.GetInstance().Error("Unable to get registry value: " + key.ToString() + " " + valueName + " creating with default value:" + defaultValue);
key.SetValue(valueName, defaultValue, kind);
}
}
catch
{
Logger.GetInstance().Error("Unable to create registry value: " + key.ToString() + " " + valueName + " with default value:" + defaultValue);
}
retVal = defaultValue;
}
if (retVal == null)
{
retVal = defaultValue;
try
{
if (create)
{
Logger.GetInstance().Error("Null registry value: " + key.ToString() + " " + valueName + " creating with default value:" + defaultValue);
key.SetValue(valueName, defaultValue, kind);
}
}
catch
{
Logger.GetInstance().Error("Unable to create null registry value: " + key.ToString() + " " + valueName + " with default value:" + defaultValue);
}
}
return retVal;
}
示例8: ReadVersionValue
internal static Version ReadVersionValue(RegistryKey mshsnapinKey, string name, bool mandatory)
{
string temp = ReadStringValue(mshsnapinKey, name, mandatory);
if (temp == null)
{
s_mshsnapinTracer.TraceError("Cannot read value for property {0} in registry key {1}",
name, mshsnapinKey.ToString());
Dbg.Assert(!mandatory, "mandatory is true, ReadStringValue should have thrown exception");
return null;
}
Version v;
try
{
v = new Version(temp);
}
catch (ArgumentOutOfRangeException)
{
s_mshsnapinTracer.TraceError("Cannot convert value {0} to version format", temp);
throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name);
}
catch (ArgumentException)
{
s_mshsnapinTracer.TraceError("Cannot convert value {0} to version format", temp);
throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name);
}
catch (OverflowException)
{
s_mshsnapinTracer.TraceError("Cannot convert value {0} to version format", temp);
throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name);
}
catch (FormatException)
{
s_mshsnapinTracer.TraceError("Cannot convert value {0} to version format", temp);
throw PSTraceSource.NewArgumentException("name", MshSnapinInfo.VersionValueInCorrect, name, mshsnapinKey.Name);
}
s_mshsnapinTracer.WriteLine("Successfully converted string {0} to version format.", v);
return v;
}
示例9: DeleteValue
/// <summary>
/// Delete a value
/// </summary>
/// <param name="key">Registry Key Path</param>
internal static void DeleteValue(RegistryKey root, string subKey, string name)
{
RegistryKey rk = null;
try {
rk = root.OpenSubKey( subKey, true );
if ( rk != null ) {
rk.DeleteValue( name );
iAlteredValuesCount++;
Log.AppendString( logfile, "Deleted value: " + rk.ToString() + "\\" + name + Environment.NewLine );
Display.UpdateStatus( "Deleted: " + root.ToString() + "\\...\\" + name, ConsoleColor.Red );
}
}
catch ( Exception ex ) {
Log.AppendException( logfile, ex );
}
finally {
if ( rk != null ) {
rk.Close();
rk = null;
}
subKey = null;
name = null;
}
}
示例10: copyipv6address
void copyipv6address(RegistryKey source, uint luidindex, uint iftype, RegistryKey dest)
{
if (source == null)
{
Trace.WriteLine("No IPv6 Config found");
return;
}
//Construct a NET_LUID & convert to a hex string
ulong prefixval = (((ulong)iftype) << 48) | (((ulong)luidindex) << 24);
// Fix endianness to match registry entry & convert to string
byte[] prefixbytes = BitConverter.GetBytes(prefixval);
Array.Reverse(prefixbytes);
string prefixstr = BitConverter.ToInt64(prefixbytes,0).ToString("x16");
Trace.WriteLine("Looking for prefix "+prefixstr);
string[] keys = source.GetValueNames();
foreach (string key in keys) {
Trace.WriteLine("Testing "+key);
if (key.StartsWith(prefixstr)) {
Trace.WriteLine("Found "+key);
//Replace prefix with IPv6_Address____ before saving
string newstring="IPv6_Address____"+key.Substring(16);
Trace.WriteLine("Writing to " + dest.ToString()+" "+newstring);
dest.SetValue(newstring, source.GetValue(key));
}
}
Trace.WriteLine("Copying addresses with prefix "+prefixstr+" done");
}
示例11: GetAllValues
/// <summary>
/// Returns all values from registry path, using specified Registry key
/// </summary>
/// <param name="path">path to registry key beginning </param>
/// <returns>Dictionary w/ values or empty</returns>
public static Dictionary<string, object> GetAllValues(RegistryKey rootKey, string path)
{
Dictionary<string, object> arValues = new Dictionary<string, object>();
//KeyValuePair<string, object>[] arValues1 = null;
string[] arKeys = null;
//string subPath = "";
RegistryKey key = null;
//RegistryKey rootKey = Registry.CurrentUser;
if(path == null)
{
Log4cs.Log("No path specified for Registry!", Importance.Error);
return arValues;
}
if(path.StartsWith("\\"))
path = path.Substring(1);
Log4cs.Log("Get values from: {0}\\{1}", rootKey.ToString(), path);
try
{
key = rootKey.OpenSubKey(path);
arKeys = key.GetValueNames();
Log4cs.Log(Importance.Debug, "Got " + arKeys.Length + " values in {0}\\{1}", rootKey.ToString(), path);
if(arKeys.Length > 0)
{
for(int i = 0; i < arKeys.Length; i++)
{
try
{
arValues[arKeys[i]] = key.GetValue(arKeys[i]).ToString();
} catch(Exception)
{
Log4cs.Log(Importance.Warning, "Duplicate key [" + arKeys[i] + "]");
}
//Log4cs.Log("\t" + arKeys[i] + "->" + key.GetValue( arKeys[i] ).ToString() );
}
} // END IF
} catch(Exception ex)
{
Log4cs.Log(Importance.Error, "Error listing " + rootKey.ToString() + "\\" + path);
Log4cs.Log(Importance.Debug, ex.ToString());
//return m_arValues;
}
try
{
key.Close();
rootKey.Close();
} catch(Exception) { }
return arValues;
}
示例12: doFoundWinRegKey
private static void doFoundWinRegKey(RegistryKey rCore, StringBuilder logger)
{
doLogSetEnvVarInfo(string.Format("Found Windows registry key {0}", rCore.ToString()), logger);
}
示例13: Check
protected override void Check(ListView.ListViewItemCollection collection, string ext, RegistryKey rk, IWICBitmapDecoderInfo info)
{
DataEntry[] de = new DataEntry[] { new DataEntry("File Extension", ext)};
string progid = CheckStringValue(collection, rk, null, de);
if (!string.IsNullOrEmpty(progid))
{
using (RegistryKey r = OpenSubKey(collection, rk, "OpenWithProgids", de))
{
if (r != null)
{
if (Array.IndexOf(r.GetValueNames(), progid) < 0)
{
collection.Add(this, "Registry value is missing.", de, new DataEntry("Expected Values", progid), new DataEntry("Key", rk.ToString()));
}
}
}
using (RegistryKey r = OpenSubKey(collection, rk, string.Format(CultureInfo.InvariantCulture, "OpenWithList\\{0}", PhotoViewerDll), de))
{
}
using (RegistryKey r = OpenSubKey(collection, rk, "ShelExt\\ContextMenuHandlers\\ShellImagePreview", de))
{
CheckValue(collection, r, null, new string[] { PhotoGalleryGuid }, de);
}
using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, progid, new DataEntry[0]))
{
CheckStringValue(collection, r, null, de);
using (RegistryKey r1 = OpenSubKey(collection, r, "DefaultIcon", new DataEntry[0]))
{
CheckStringValue(collection, r1, null, de);
// TODO get and check icon
}
using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open\\command", new DataEntry[0]))
{
CheckValue(collection, r1, null, new string []{"%SystemRoot%\\System32\\rundll32.exe \"%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll\", ImageView_Fullscreen %1"}, de);
}
using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open", new DataEntry[0]))
{
CheckValue(collection, r1, "MuiVerb", new string[] { "@%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll,-3043" }, de);
}
using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open\\DropTarget", new DataEntry[0]))
{
CheckValue(collection, r1, "Clsid", new string[] { PhotoGalleryGuid }, de);
}
using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\printto\\command", new DataEntry[0]))
{
CheckValue(collection, r1, null, new string[] { "%SystemRoot%\\System32\\rundll32.exe \"%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll\", ImageView_PrintTo /pt \"%1\" \"%2\" \"%3\" \"%4\"" }, de);
}
}
}
using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, string.Format(CultureInfo.InvariantCulture, "SystemFileAssociations\\{0}", ext), new DataEntry[0]))
{
using (RegistryKey r2 = OpenSubKey(collection, r, "ShellEx\\ContextMenuHandlers\\ShellImagePreview", de))
{
CheckValue(collection, r2, null, new string[] { PhotoGalleryGuid }, de);
}
}
}
示例14: DeleteAllValues
/// <summary>
/// Delete all values found in a Registry key.
/// </summary>
/// <param name="key">Registry Key Path</param>
internal static void DeleteAllValues(RegistryKey root, string subKey)
{
RegistryKey rk = null;
string[] valueNames = null;
try {
rk = root.OpenSubKey( subKey, true );
if ( rk != null ) {
// Retain a list of value names for this key
valueNames = rk.GetValueNames();
// Return to caller if no values are found
if ( valueNames != null && valueNames.Length != 0 ) {
// Delete each value in this key
foreach ( string valueName in valueNames ) {
rk.DeleteValue( valueName );
iDeletedValuesCount++;
Log.AppendString( logfile, "Deleted value: " + rk.ToString() + "\\" + valueName + Environment.NewLine );
Display.UpdateStatus( "Deleted: " + root.ToString() + "\\...\\" + valueName, ConsoleColor.Red );
}
}
}
}
catch ( Exception ex ) {
// Record exceptions in the log file
Log.AppendException( logfile, ex );
}
finally {
// Finally, cleanup and prepare variables for garbage collection
if ( rk != null ) {
rk.Close();
rk = null;
}
valueNames = null;
subKey = null;
}
}
示例15: SetValue
/// <summary>
/// Writes a byte[] value to key
/// </summary>
/// <param name="key">Registry Key Path</param>
/// <param name="value">32-bit binary value</param>
internal static void SetValue(RegistryKey root, string subKey, string name, byte[] value)
{
RegistryKey rk = null;
try {
rk = root.OpenSubKey( subKey, true );
if ( rk != null ) {
rk.SetValue( name, value, RegistryValueKind.Binary );
iAlteredValuesCount++;
//Log.AppendString( logfile, "Set value: " + rk.ToString() + "\\" + name + " = " + value + Environment.NewLine );
Display.UpdateStatus( "Changed: " + root.ToString() + "\\...\\" + name + " = [BINARY]" );
}
}
catch ( Exception ex ) {
Log.AppendException( logfile, ex );
}
finally {
if ( rk != null ) {
rk.Close();
rk = null;
}
subKey = null;
name = null;
}
}