locked
Windows Mobile Registry DeleteSubKey doesn't always work RRS feed

  • Question

  • I am building an application for streamlining bluetooth pairing on a Windows Mobile 6.1 device. I am setting registry values and deleting them when a new device is paired. The problem is, the registry key is not always deleted, even when the method executes without error. Here is how I am deleting the key. What might cause the key to stay there?

    I've tried using a registry editor and they sometimes can't remove the key either. Usually, if I restart the device, I can remove the key. But I can't be restarting the device all the time or the application will be worthless.

    searchKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Bluetooth\\Serial\\Ports\\", true);
    
    if (searchKey != null)
    {
    	string[] keys = searchKey.GetSubKeyNames();
    	
    	foreach (string key in keys)
    	{
    		indexKey = null;
    		indexKey = Registry.LocalMachine.OpenSubKey(@"Software\\Microsoft\\Bluetooth\\Serial\\Ports\\" + key, true);
    		
    		if (indexKey != null)
    		{
    			string tempMac = key.Substring(4);
    			string port = indexKey.GetValue("PORT").ToString();
    			indexKey.Close();
    			if (port == "COM1")
    				Registry.LocalMachine.DeleteSubKey(@"Software\\Microsoft\\Bluetooth\\Serial\\Ports\\" + key, true);
    		}
    	}
    	searchKey.Close();
    }



    • Edited by teynon Wednesday, May 30, 2012 3:27 PM additional information
    Wednesday, May 30, 2012 3:21 PM

All replies

  •  

    Hello,

     

    Do you try to restart the device to check if the value is changed?

    As far as I know, some registry keys are not be changed for OEM settings.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 1, 2012 7:08 AM
  • "I've tried using a registry editor and they sometimes can't remove the key either. Usually, if I restart the device, I can remove the key. But I can't be restarting the device all the time or the application will be worthless."

    ^^^ Yes I've tried restarting. That's the point. Let me toss out a scenario here:

    Every time you start playing your favorite video game, you have to restart your computer or mobile device. Sounds to me like your favorite game wouldn't be your favorite game after the 2nd or third time.

    Thursday, June 14, 2012 5:47 PM