Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 17th, 2006, 12:11 PM
ehsanking ehsanking is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 207 ehsanking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 3 m 51 sec
Reputation Power: 4
Talking Problem writing multiple values to registery

Hi all i am usiing this code to write mulitiple values to registery but it only write one value. could any one help me make this code so that it write multiple values to registery. Currently it only writes nickname but not pwd value!!
I tried this but gave me error :


Code:

'Save the value to the registry
    SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text "pwd", strString



complete code :


Code:

Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long




Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Save a string to the key
    RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
    'close the key
    RegCloseKey Ret
End Sub
Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Set the key's value
    RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
    'close the key
    RegCloseKey Ret
End Sub

Private Sub Command14_Click()
'Dim strString As String
    Dim strString As String
    'Ask for a value
    'strString = InputBox("Please enter a value to be saved as a binary value in the registry.", App.Title)
    

    'Save the value to the registry


    SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname", strString

'    SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text, "pwd", strString ===> did not work
    
 
End Sub

Reply With Quote
  #2  
Old June 26th, 2006, 01:13 AM
Punch Punch is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Australia
Posts: 5 Punch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 9 sec
Reputation Power: 0
Hey,

Your first problem is that your function call does not match the signature. You need to remove the commas because they are breaking the string up into seperate parameters. From the looks of what you've provided, the code you want in your Command4_Click() event should be:

Code:
Private Sub Command14_Click()

Dim strPwd As String

'Ask for a value
strPwd = InputBox("Please enter a value", App.Title)
    
'Save the values to the registry
SaveString (HKEY_CURRENT_USER, "Software\xyz\" + 
Text6.Text, "nickname", Text7.Text)

SaveString (HKEY_CURRENT)USER, "Software\xyz\" + 
Text6.Text, "pwd", strPwd)
 
End Sub


Which I believe should save the two pieces of information. The biggest problem with your original code is the following line:
Code:
SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text "pwd", strString

You seem to be a little confused about how to call a function and what the parameters are.

SaveString is a function. The items in brackets that follow the function declaration are its parameters. Each parameter is seperated by a comma, so in the following function specification:
Code:
Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)

A function is created called SaveString which expects to be passed the following items every time it is called:
  • hKey, a Long number identifying the registry key into which the string will be saved (in your function call this is HKEY_CURRENT_USER)
  • strPath, a String identifying the path to which the value will be written. (in your function call this is "Software\xyz\" + Text6.text)
  • strValue, a String identifying the value against which the data will be saved. The value is essentially the key or the name that is assigned to the data, and will be used lata to retrieve the desired information. (in your function call you are using "nickname" as the value, and the second call that I added to SaveString uses "pwd" as the value)
  • strData, a String containing the data that will be saved to the registry.

Your function call is the line:
Code:
SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text, "pwd", strString


SaveString identifies the function, and then each item following is a parameter. Every comma denotes a new parameter, and these parameters must match exactly the ones specified in teh function declaration.

It may help when starting out for you to copy the function declaration and paste it in wherever you are planning on calling the function from, then replace each parameter with the value you wish to take. This will ensure that you are sending the information that the function needs.

The SaveString function is only designed to save one string at a time, so to create two entries you need to call the function twice, like I did in the code listing at the beginning.

I know it's a long post, but it should provide you with the information you need to solve your problem It seems to me that you don't have a lot of experience in VB, so you may be better off starting with a couple of introductory tutorials from somewhere on the 'net instead of jumping straight into registry coding.

Good luck with everything!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Problem writing multiple values to registery


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT