EzDevInfo.com

registry interview questions

Top registry frequently asked interview questions

Registry vs. INI file for storing user configurable application settings

I'm a new Windows programmer and I'm not sure where I should store user configurable application settings. I understand the need to provide a user friendly means for the user to change application settings, like an Edit | Settings form or similar. But where should I store the values after the user hits the Apply button on that form?

What are the pros and cons of storing settings in the Windows registry vs. storing them in a local INI file or config file or similar?


Source: (StackOverflow)

Requested registry access is not allowed

I'm writing a tweak utility that modifies some keys under HKEY_CLASSES_ROOT.

All works fine under Windows XP and so on. But I'm getting error Requested registry access is not allowed under Windows 7. Vista and 2008 I guess too.

How should I modify my code to add UAC support?


Source: (StackOverflow)

Advertisements

Reading registry keys in c#

I've developed an application and installed in a client system. In my application I need to get the install path of my application in the client system. It has a registry entry in:

HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\[AppPath]

How can I read the AppPath using C#?


Source: (StackOverflow)

Command line to remove an environment variable from the OS level configuration

Windows has setx command

Description:
    Creates or modifies environment variables in the user or system
    environment.

So you can set a variable like this

setx FOOBAR 1

and you can clear the value like this

setx FOOBAR ""

However, the variable does not get removed, it stays in the registry

foo

So how would you actually remove the variable?


Source: (StackOverflow)

Why does the Windows registry exist? [closed]

this is more OS architecture question than programming directly, but still. Why was the Windows registry created as a completely separate subsystem for storing system/application settings? In *nix OS'es there is /etc directory which is perfectly understandable, as filesystem is a natural hierarchical way for storing settings, while Microsoft decided to create a completely outside hierarchical subsystem, which seems to be a foolish investment, why didn't they just use a filesystem hierarchy?


Source: (StackOverflow)

Java Error opening registry key

I get this error when I try to do anything with Java in command prompt:

Error opening registry key 'Software\JavaSoft\Java Runtime Environment.3'
Error: could not find Java.dll
Error: could not find Java 2 Runtime Environment

I did screw around with deleting Java directories and registry a few days ago. I restarted computer and java was still working fine, then i restarted it again today and now I get this error. I have tried uninstalling and reinstalling but that doesn't seem to work. I have the latest java JRE installed and the path set in the environment variables. Anyone have any clue how to fix this?


Source: (StackOverflow)

How to check if a registry value exists using C#?

How to check if a registry value exists by C# code? This is my code, I want to check if 'Start' exists.

public static bool checkMachineType()
{
    RegistryKey winLogonKey = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\services\pcmcia", true);
    string currentKey= winLogonKey.GetValue("Start").ToString();

    if (currentKey == "0")
        return (false);
    return (true);
}

Source: (StackOverflow)

Is it possible to modify a registry entry via a .bat/.cmd script?

Is it possible to modify a registry value (whether string or DWORD) via a .bat/.cmd script?


Source: (StackOverflow)

How to prevent Windows from caching Com Class info?

Windows 7 is caching some of the COM class information. Older OSs didn't do this. After the OS looks up theHKCU\Software\Classes\CLSID\{GUID}\LocalServer32 value, it caches the value, and doesn't look it up again.

When we update our software, we place the new updates in a different directory, and then update the HKCU\Software\Classes\CLSID\{GUID}\LocalServer32 value to reflect the new path. The next time the software runs, it will use the latest files if running under older Windows OSs. However, on Windows 7, it will continue to use the older file, until the OS is rebooted.

I ran process monitor, and discovered that under Windows 7, it never reads the registry key again, after the first read. On older OSs, it reads that key every time.

My question is: Is there any way to force Windows 7 to re-read the LocalServer32 information from the HKCU hive each time a new out of proc COM object is created?


Source: (StackOverflow)

How do I totally delete/reset bluetooth settings in Windows 7 [closed]

I have a windows 7 machine that I've been using to experiment with several serial over bluetooth devices. I now have a couple of problems that I would like to solve without having to re-image my machine.

The first problem is that I've had to uninstall and reinstall these devices so much that I'm now up to serial port 50.

The second problem is that one particular device (that acts as a master) will only let me talk to it once before the serial port disconnects and forces me to reconnect to the computer.

When working with a fresh install of Windows 7 using the same bluetooth dongle, I don't have the disconnect problem or the high com port problem, however, I prefer not to re-image my machine if I can help it. Anyone have any ideas how I can totally uninstall bluetooth and delete all of the com ports so I can start with clean bluetooth settings?


Source: (StackOverflow)

WIX will not add HKLM registry setting during Windows 7 install

Good Morning,

I have written a WiX installer that works perfectly with Windows XP but when installing to a Windows 7 box I am running into difficulty with Registry Entries. What I need to do is add a HKLM entry as well as the registry entry for the program to show in the start menu. Here is the code i am using for both types of entry:

<!-- Create the registry entries for the program -->
<DirectoryRef Id="TARGETDIR">
  <Component Id="RegistryEntriesInst" Guid="...">
    <RegistryKey Root="HKLM"
                 Key="Software\$(var.Manufacturer)\$(var.ProductName)"
          Action="createAndRemoveOnUninstall">
      <RegistryValue 
          Type="string" 
          Name="installed" 
          Value="true" 
          KeyPath="yes"/>
    </RegistryKey>
  </Component>
  <Component Id="RegistryEntriesVer" Guid="...">
    <RegistryKey Root="HKLM"
                 Key="Software\$(var.Manufacturer)\$(var.ProductName)"
          Action="createAndRemoveOnUninstall">
      <RegistryValue 
          Type="string" 
          Name="version" 
          Value="$(var.ProductVersion)" 
          KeyPath="yes"/>
    </RegistryKey>
  </Component>
</DirectoryRef>

<!-- To add shortcuts to the start menu to run and uninstall the program-->
<DirectoryRef Id="ApplicationProgramsFolder">
  <Component Id="ApplicationShortcut" Guid="...">
    <Shortcut Id="ApplicationStartMenuShortcut"
              Name="$(var.ProductName)"
              Description="..."
              Target="[SERVERLOCATION]$(var.Project.TargetFileName)"
              WorkingDirectory="SERVERLOCATION"/>
    <Shortcut Id="UninstallProduct"
                  Name="Uninstall $(var.ProductName)"
                  Description="..."
                  Target="[System64Folder]msiexec.exe"
                  Arguments="/x [ProductCode]"/>
    <RemoveFolder Id="SERVERLOCATION" On="uninstall"/>
    <RegistryValue 
        Root="HKCU" 
        Key="Software\$(var.Manufacturer)\$(var.ProductName)" 
        Name="installed" 
        Type="integer" 
        Value="1" 
        KeyPath="yes"/>
    </Component>
</DirectoryRef>

Any help/suggestions that can be given will be appreciated. On a side note the registry permissions are the same on the XP and 7 computers.

Thanks


Source: (StackOverflow)

How can I get the value of a registry key from within a batch script?

I need to use a REG QUERY command to view the value of a key and set the result into a variable with this command:

FOR /F "tokens=2* delims=    " %%A IN ('REG QUERY "KeyName" /v ValueName') DO SET Variable=%%B

But if the key doesnt exists i get an error shown in the console. I need to hide this error! I tried putting a 2>nul after the command to stop the stderr, but this works if i only call the command:

REG QUERY "KeyName" /v ValueName 2>nul

If i put it into the FOR command like this:

FOR /F "tokens=2* delims=    " %%A IN ('REG QUERY "KeyName" /v ValueName') DO SET Variable=%%B 2>nul

The error is shown. So does anyone know how to hide the error? Or maybe another command too see if a key exists or not?

Thanks

PS: I'm using Windows XP


Source: (StackOverflow)

Run the application at Windows startup

I made my WPF application to startup with the next code below. The process run on the process manager tool after the restart, but I can't see the application on the screen. When I open the same .exe file from the startup registery value the program runs perfect.

what can I do to fix it up ?

//*** The code I am using ***\\\

// The path to the key where Windows looks for startup applications
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);


// Add the value in the registry so that the application runs at startup
rkApp.SetValue("MyApp", Application.ExecutablePath.ToString());

Source: (StackOverflow)

Windows 64-bit registry v.s. 32-bit registry

I heard on Windows x64 architecture, in order to support to run both x86 and x64 application, there is two separate/different sets of Windows registry -- one for x86 application to access and the other for x64 application to access? For example, if a COM registers CLSID in the x86 set of registry, then x64 application will never be able to access the COM component by CLSID, because x86/x64 have different sets of registry?

So, my question is whether my understanding of the above sample is correct? I also want to get some more documents to learn this topic, about the two different sets of registry on x64 architecture. (I did some search, but not found any valuable information.)

thanks in advance, George


Source: (StackOverflow)

How to manually register ClickOnce file associations after installation?

Microsoft's ClickOnce deployment system offers an easy-to-use file association manager which is built into the Visual Studio deployment process. Developers can add up to 8 file associations which will automatically be associated with their application when the user runs the ClickOnce installer.

I'd like to take it one step further, though: I want to allow users to manually add or remove additional file associations after installation from within my application.

I have two motivations for accomplishing this:

  • I won't "force" additional file associations on the user, which is how file associations through ClickOnce deployments are handled.
  • Users can add or remove their own unique file associations at their leisure.

The tricky part: Directly associating a filetype with an executable is not compatible with ClickOnce deployments

Unlike traditional Windows applications, ClickOnce applications are not launched directly via their executable. Instead, they are launched via a special .appref-ms shortcut which handles the ClickOnce magic behind the scenes (automatic updates, locating the executable files in an obfuscated directory in %LOCALAPPDATA%, etc).

If a ClickOnce-deployed app is opened directly via its executable, automatic updates are disabled and ClickOnce-specific methods will no longer function. Because of this, traditional registry file associations are not possible for my use case.

How Visual Studio handles ClickOnce file associations

The image below demonstrates Visual Studio 2010's built-in ClickOnce file association manager. This information is stored in the application's .manifest file and is added to the Windows registry upon installation.

VS2010's ClickOnce File Association Manager

I've done some digging through my registry and have identified several entries made by the ClickOnce installer to associate filetypes with the ClickOnce deployed application.

An example registry key for a ClickOnce filetype association I found in my registry:

rundll32.exe dfshim.dll, ShOpenVerbExtension {ae74407a-1faa-4fda-9056-b178562cf98f} %1

Where {ae74407a-1faa-4fda-9056-b178562cf98f} is a GUID used in several other locations in the registry for the associated application.

My goal is to learn what information must be added to the registry (programmatically) to manually associate files with a ClickOnce deployed application.

Any help is appreciated!


Source: (StackOverflow)