Solved

changing registry settings using vb

Posted on 2003-11-13
7
184 Views
Last Modified: 2010-05-18
i am working on some desktop applications and i require to enter the registry(regedit) for some settings..... can i do this with the help of vb?if yes then please give example commands!
0
Comment
Question by:devdasvirus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 7

Accepted Solution

by:
_agj_ earned 60 total points
ID: 9745691
To open keys, edit em etc u need to use the api calls like RegOpenKey etc.

http://www.mentalis.org/apilist/RegOpenKey.shtml

check out the api listing for the otehr registry stuff in it. ALso there shud be a gud example there.

Wihtout usign the api , u can use inbuilt vb fns like:

GetSetting
DeleteSetting
SaveSetting

these however, only allow u to use keys under the VB applications section.

use api for full acess.
0
 
LVL 1

Expert Comment

by:atp_expert
ID: 9747035
Use
RegOpenKey to open the key
RegSetValueEx to write value to registry
RegqueryValuEx to read the registry
regclosekey to close the regsitry handle.
0
 
LVL 4

Expert Comment

by:wulfshayde
ID: 9747638
Do you need to edit existing registry keys? Or is your purpose to make and maintain program based ones?
0
 
LVL 1

Expert Comment

by:RocketMan801
ID: 9749177
if you need to read or writte in specific areas in the windows registry you need to use api calls, for example, if you want to get the path where warcraft3 is installed, knowing that u have to read the value:
InstallPath
stored in:
HKEY_CURRENT_USER\Software\Blizzard Entertainment\Warcraft III

you can use this func:

'///// API declaration ans stuff
Public Const HKEY_LOCAL_MACHINE As Long = &H80000002
Public Const HKEY_CURRENT_USER = &H80000001

'Return codes from Registration functions
Public Const ERROR_SUCCESS As Long = 0
Public Const ERROR_BADDB As Long = 1009
Public Const ERROR_BADKEY As Long = 1010
Public Const ERROR_CANTOPEN As Long = 1011
Public Const ERROR_CANTREAD As Long = 1012
Public Const ERROR_CANTWRITE As Long = 1013
Public Const ERROR_OUTOFMEMORY As Long = 14
Public Const ERROR_INVALID_PARAMETER As Long = 87
Public Const ERROR_ACCESS_DENIED As Long = 5
Public Const ERROR_MORE_DATA As Long = 234
Public Const ERROR_NO_MORE_ITEMS As Long = 259
Public Const KEY_ALL_ACCESS As Long = &H3F
Public Const REG_OPTION_NON_VOLATILE As Long = 0

Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal sSubKey As String, hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal sKeyValue As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, nSizeData As Long) As Long

'//// the function ifself
Public Function Getw3Path() As String
 
   Dim hKey As Long
   Dim nSizeData As Long
   Dim Data As String
   
   Const sSubKey = "Software\Blizzard Entertainment\Warcraft III"
   Const sKeyValue = "InstallPath"

   If RegOpenKey(HKEY_CURRENT_USER, sSubKey, hKey) = ERROR_SUCCESS Then
   
      Data = Space(260)
      nSizeData = Len(Data)
     
      If RegQueryValueEx(hKey, sKeyValue, 0&, 0&, ByVal Data, nSizeData) = ERROR_SUCCESS Then
         Getw3Path = TrimNull(Data)
      End If
     
      Call RegCloseKey(hKey)
   
   End If

End Function

'/required function
Private Function TrimNull(startstr As String) As String

  Dim pos As Integer

  pos = InStr(startstr, Chr$(0))
  If pos Then
      TrimNull = Left$(startstr, pos - 1)
      Exit Function
  End If
  TrimNull = startstr
 
End Function
'// i recomend u http://www.mvps.org/vbnet to get more info and example projects

BUT,  if what u need is simpler than that, and you just want to store your app settings on the reg, then the easiest way to do so is:
'//save value
SaveSetting "App1", "config", "Value1", Text1.Text 'or what you want

'//get the value
Text1.Text = GetSetting("App1", "config", "Value1")
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10548281
Moderator, my recommended disposition is:

    Accept _agj_'s comment(s) as an answer.

Dan Rollins -- EE database cleanup volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question