Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

Excel VBA : read registry key values on a remote computer using WMI

// VBA code to paste in an module
Function ORACLEHOMES(strComputer As String)
    Const HKEY_LOCAL_MACHINE = &H80000002
    ORACLEHOMES = ""
    Dim strKeyPath
    Dim arrSubKeys
    Dim oReg
    Dim strValueName
    Dim strValue
    'strComputer = "."
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\ORACLE"
    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
    For Each subkey In arrSubKeys
        If Left(subkey, 4) = "KEY_" Then
            strValueName = "ORACLE_HOME"
            oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, strValueName, strValue
            If ORACLEHOMES = "" Then
                ORACLEHOMES = strValue
            Else
                ORACLEHOMES = ORACLEHOMES & ";" & strValue
            End If
        End If
    Next
End Function

Open/Creates a Base Key in the Registry

// open a Base Key in the registry

       public static RegistryKey GetKey(string baseKey)
        {
            RegistryKey key;
            try
            {
                key = Registry.LocalMachine.OpenSubKey(baseKey, true);

                if (key == null)
                {
                    key = Registry.LocalMachine.CreateSubKey(baseKey);
                }
                else
                {
                    MessageBox.Show("Base key resolved");
                }
            }
            catch (Exception e)
            {
                return null;
            }
            return key;
        }

Solution for a common problem: "Cannot write to the registry"

Original (not working):
 RegistryKey reg = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop");
 reg.SetValue("WallpaperStyle", "1");    //2 for stretch



Modified (working):
 RegistryKey reg = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
 reg.SetValue("WallpaperStyle", "1");    //2 for stretch

 

Wallpaper.reg

[HKEY_CURRENT_USER\Control Panel\Desktop]
"Wallpaper"="C:\\wallpaper.bmp"

Basic Registry Access Example

// Basic Registry Access Example

RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\Company\Priduct\Version");
if (key!=null)
{
string ini = key.GetValue("localinifile","").ToString();
key.Close();
}

Change default action of non-URLs in Internet Explorer location bar

Turn this into a .reg file for people to use:

REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchURL]
""="http://www.yoursite.com/search?&q=%s"
"provider"="x"
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS