Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

changing registry settings using vb

Posted on 2003-11-13
7
Medium Priority
?
189 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
7 Comments
 
LVL 7

Accepted Solution

by:
_agj_ earned 240 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

Independent Software Vendors: 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

927 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