Winston Posted March 24, 2003 Posted March 24, 2003 hey guys i was wondering how do u check if a particular key exists i want to know that and also how to check if the registry value exists Quote
*Experts* Nerseus Posted March 24, 2003 *Experts* Posted March 24, 2003 You'll want to use the Registry object. For instance, to see if there's a key exists: Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft2"); if(key==null) Debug.WriteLine("Key does not exist"); else Debug.WriteLine("Key does exist"); To see if a value exists: Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft"); if(key!=null) { if(key.GetValue("hello")==null) Debug.WriteLine("Value does not exist"); else Debug.WriteLine("Value does exist"); } -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Leaders dynamic_sysop Posted March 24, 2003 Leaders Posted March 24, 2003 (edited) Dim strKey As Microsoft.Win32.RegistryKey strKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\MSNChat\4.0") 'This retreives the registry key ( just have to add as nessecary to it ) thats just an example of opening a registry key Edited March 24, 2003 by dynamic_sysop Quote
Winston Posted March 25, 2003 Author Posted March 25, 2003 heh thanks guys ummm how exactly do u delete a sub key?.. Quote
Guest mutant Posted March 25, 2003 Posted March 25, 2003 This should do it. Imports Microsoft.Win32 ... dim key as RegistryKey = Registry.LocalMachine 'Of course you can pick anything 'instead of Local Machine 'This will delete the subkey and it wont work if you have 'any subkeys to that given subkey. key.deletesubkey("path to whatever you wish to delete") 'or 'This will delete that subkey and all subkeys of that subkey key.deletesubkeytree("path to whatever you wish to delete") Quote
hog Posted March 25, 2003 Posted March 25, 2003 So is this method of accessing registry keys better than using SaveSetting and GetSetting? Quote My website
Guest mutant Posted March 25, 2003 Posted March 25, 2003 Its easy and its better. Save setting doesnt allow you to choose the location of key i think. Quote
Leaders dynamic_sysop Posted March 25, 2003 Leaders Posted March 25, 2003 SaveSetting doesnt allow you to tell it the location as far as "HKEY_CURRENTUSER" etc..., only allows you to create a named key, in the default place (eg: hkey_currentuser\software\visual basic\YOUR PROGRAMME NAME ) Quote
Winston Posted March 26, 2003 Author Posted March 26, 2003 hmmmm i cant quite get it to work mutant i used this code u gave a while back ago where u save ur app into load up with windows but now i duno how to delete it heres the saving code Dim key As RegistryKey Dim subkey As RegistryKey key = Registry.LocalMachine subkey = key.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run\") subkey.SetValue(Application.ProductName, Application.StartupPath & "\Task Schedular.exe") Call subkey.Close() Call key.Close() Quote
Guest mutant Posted March 26, 2003 Posted March 26, 2003 You didnt put the slashes in the path. Change the code to: Dim key As RegistryKey Dim subkey As RegistryKey key = Registry.LocalMachine subkey = key.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run\putthenameofapphere")'or whatever you want to call the key subkey.SetValue(Application.ProductName, Application.StartupPath & "Task Schedular.exe") subkey.Close() key.Close() I tried this and it works OK. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.