vb6 Somalia
  • 14 years ago

    'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
    'Add 1 CommandButton to your form (named Command1),
    'And 1 TextBox (named Text1).
    'Type in the TextBox you desirable windows registered name.
    'After that press the button. To see the results, right-click on 'My Computer'
    'Icon on your desktop.

    'Insert this code to the module :

    Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
    (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
    (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As _
    Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
    Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Public Const HKEY_LOCAL_MACHINE = &H80000002

    'Insert this code to your form:

    Sub WriteRegistry(ByVal Group As Long, ByVal Section As String, ByVal Key As _
    String, NewVal As String)
    Dim lResult As Long, lKeyValue As Long
    Dim InLen As Long
    On Error Resume Next
    lResult = RegOpenKey(Group, Section, lKeyValue)
    InLen = Len(NewVal)
    lResult = RegSetValueEx(lKeyValue, Key, 0&, 1&, NewVal, InLen)
    lResult = RegFlushKey(lKeyValue)
    lResult = RegCloseKey(lKeyValue)
    End Sub

    Private Sub Command1_Click()
    WriteRegistry HKEY_LOCAL_MACHINE, _
    "SOFTWARE\Microsoft\Windows\CurrentVersion", "RegisteredOwner", Text1
    End Sub



  • 14 years ago

    Hi DoctorMahdi

    can you simplify this source code i am novice



  • 14 years ago

    Doctor Mahdi,

    Thank you for all of your contributions to this site.  May I suggest that you submit code snippets such as this one as resources instead. 

    The forums are intended to be used for the submission of development related problems and posts fade into the archives after a matter of a few days.  If you have a code snippet, article or tutorial,  providing it is your own and you are not infringing anyones copyright or going against their wishes, please feel free to share it with others using the link above.

    Thanks once again,


  • 14 years ago

    Hi Sync

    thanks for your advance


    DoctorMahdiIdea [Idea]

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare