Results 1 to 9 of 9

Thread: Registry Help - Should be dead easy

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99

    Registry Help - Should be dead easy

    ok guys, i want to check a key exists if yes then exit sub, but if it dont exist create it and then exit sub.

    <vbcode>
    Public Sub Check_Reg()
    If Registry.LocalMachine.Name = ("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator") = True Then
    Debug.WriteLine("Key Exists")

    Else
    Registry.LocalMachine.CreateSubKey("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator")
    End If
    End Sub
    </vbcode>


    thats what i got, dunno if its right guys, Help me please, tnx guys, u all rule

    BTW i am useing .NET

  2. #2
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    not sure if this is the best way but I know it will get it done.

    Code:
    Dim RegKey As RegistryKey
    Dim s As String
    RegKey = Registry.LocalMachine.OpenSubKey("Software\A", True )
    Try 
         s = RegKey.ToString()
    Catch 
         RegKey = Registry.LocalMachine.CreateSubKey("Software\A")
    End Try
    you will also need to import Microsoft.Win32

    Jeremy

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This contains more functions & and many flags for Registry use.
    Attached Files Attached Files

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    ok dudes, u guys are mint, i think i got a bit confused as to what i was asking but, how do i create a new string, coz the key is like the folder then there is a string with a value, how to i make a string and give it a value, and then chage the value of the string later

  5. #5
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    I'll give you my custom function for creating file associations. You should be able to figure it from that:-

    VB Code:
    1. Public Function AddAssociation(ByVal fExt As String, ByVal appName As String, ByVal appPath As String) As Boolean
    2.   Try
    3.        Dim extKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(fExt)
    4.        extKey.SetValue("", appName)
    5.        Dim appKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(appName)
    6.        appKey.SetValue("", appName & " File")
    7.        Dim shellKey As RegistryKey = appKey.CreateSubKey("shell")
    8.        Dim openKey As RegistryKey = shellKey.CreateSubKey("open")
    9.        Dim commKey As RegistryKey = openKey.CreateSubKey("command")
    10.        commKey.SetValue("", appPath & " %1")
    11.        Return true
    12.    Catch
    13.        Return False
    14.    End Try
    15. End Function

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    sorry, im **** at this i have created a key, how do i create a string:
    this is my registry key:
    "SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator"

    how do i create a string called NWHome and give it a value of "c:\temp\scripts\cmd\NWHome.cmd"

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    ok chaps got it in the end here it is:

    <code>
    Imports Microsoft.Win32
    Public Class MyClass

    Public Sub Make_Reg
    Registry.LocalMachine.CreateSubKey("SOFTWARE\Your\Key\Here")
    End Sub

    Public Sub Make_String
    Registry.LocalMachine.CreateSubKey("SOFTWARE\Your\Key\Here").SetValue("Your_String", "Value_Of_Your_String")
    End Sub

    End Class
    </code>

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    Question again: how the hell do i close my open key this dont work

    Registry.LocalMachine.OpenSubKey("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator\Version").GetValue("Version")

    Registry.LocalMachine.Close("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator\Version")

    help!!!!

  9. #9
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271
    I don't know if you've done it yet.

    but I think it's something like:

    Code:
    Registry.LocalMachine.CloseSubKey("SOFTWARE\Trinity Expert Systems plc\Data Migration Script Creator\Version")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width