473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Registry Writing


I would like to write values to the registry and am having problems with
a very simple block of code. Here it is ...

--------------------------------------------------------
Option Compare Database
Option Explicit

Private Declare Function WriteProfileString _
Lib "kernel32" Alias "WriteProfileStringA" _
(ByVal lpszSection As String, _
ByVal lpszKeyName As String, _
ByVal lpszString As String) As Long

Public Function UpdateReg() As Integer

Dim RetVal As Integer

RetVal = WriteProfileString("\HKEY_CURRENT_USER\Software\AD OBE\Acrobat
PDFWriter", "szTitle", "mynewtitle")

If RetVal <> 1 Then
MsgBox "Problem"
Else
MsgBox "success"
End If

End Function
---------------------------------------------------------

I need to write the string "mynewtitle" to the entry "szTitle" in the
key "Acrobat PDFWriter" and although my call to "WriteProfileString"
reports 'success' (returns 1), the code fails to write the value in.

However, I can write/change entries in the registry manually with
regedit so I assume my permissions are OK.

I find it very strange that the code is not returning an error (rather
than reporting success) and I am hoping that someone can take a quick
look at my code and can tell me if there is a simple error somewhere?

I am running this on an NT 4.0 (server), with the VBA code in MSAccess
97. And I have tried both with the full path of the key (as above) and
with a simple key: "Acrobat PDFWriter".

Maybe there is something wrong with the API call? With the declaration
of the call? Or with Kernal32? But I am not sure how to check/diagnose
this. And am confused that there is no error returned.

Any tips would be a great help.

Regards,
Alan.
Nov 13 '05 #1
4 4145
Alan Searle wrote:

I would like to write values to the registry and am having problems with
a very simple block of code. Here it is ...

--------------------------------------------------------
Option Compare Database
Option Explicit

Private Declare Function WriteProfileString _
Lib "kernel32" Alias "WriteProfileStringA" _
(ByVal lpszSection As String, _
ByVal lpszKeyName As String, _
ByVal lpszString As String) As Long

Public Function UpdateReg() As Integer

Dim RetVal As Integer

RetVal = WriteProfileString("\HKEY_CURRENT_USER\Software\AD OBE\Acrobat
PDFWriter", "szTitle", "mynewtitle")

If RetVal <> 1 Then
MsgBox "Problem"
Else
MsgBox "success"
End If

End Function
---------------------------------------------------------

I need to write the string "mynewtitle" to the entry "szTitle" in the
key "Acrobat PDFWriter" and although my call to "WriteProfileString"
reports 'success' (returns 1), the code fails to write the value in.

However, I can write/change entries in the registry manually with
regedit so I assume my permissions are OK.

I find it very strange that the code is not returning an error (rather
than reporting success) and I am hoping that someone can take a quick
look at my code and can tell me if there is a simple error somewhere?

I am running this on an NT 4.0 (server), with the VBA code in MSAccess
97. And I have tried both with the full path of the key (as above) and
with a simple key: "Acrobat PDFWriter".

Maybe there is something wrong with the API call? With the declaration
of the call? Or with Kernal32? But I am not sure how to check/diagnose
this. And am confused that there is no error returned.

Any tips would be a great help.

Regards,
Alan.


I think that I've been using the wrong function. WriteProfileString is
for writing to ini files and not to the registry. Is this true? My
research goes on.

Regards.
Nov 13 '05 #2
On Fri, 03 Jun 2005 14:18:45 -0400, Alan Searle
<aj*******@xxxxyahoo.com> wrote:

Correct. WriteProfileString and its cousins are for ini files.
SaveSetting and its cousins are for a specific area of the registry -
typically good for your app's settings.
For general registry access, you'll have to use Windows API calls such
as RegOpenKeyEx

-Tom.

Alan Searle wrote:

I would like to write values to the registry and am having problems with
a very simple block of code. Here it is ...

--------------------------------------------------------
Option Compare Database
Option Explicit

Private Declare Function WriteProfileString _
Lib "kernel32" Alias "WriteProfileStringA" _
(ByVal lpszSection As String, _
ByVal lpszKeyName As String, _
ByVal lpszString As String) As Long

Public Function UpdateReg() As Integer

Dim RetVal As Integer

RetVal = WriteProfileString("\HKEY_CURRENT_USER\Software\AD OBE\Acrobat
PDFWriter", "szTitle", "mynewtitle")

If RetVal <> 1 Then
MsgBox "Problem"
Else
MsgBox "success"
End If

End Function
---------------------------------------------------------

I need to write the string "mynewtitle" to the entry "szTitle" in the
key "Acrobat PDFWriter" and although my call to "WriteProfileString"
reports 'success' (returns 1), the code fails to write the value in.

However, I can write/change entries in the registry manually with
regedit so I assume my permissions are OK.

I find it very strange that the code is not returning an error (rather
than reporting success) and I am hoping that someone can take a quick
look at my code and can tell me if there is a simple error somewhere?

I am running this on an NT 4.0 (server), with the VBA code in MSAccess
97. And I have tried both with the full path of the key (as above) and
with a simple key: "Acrobat PDFWriter".

Maybe there is something wrong with the API call? With the declaration
of the call? Or with Kernal32? But I am not sure how to check/diagnose
this. And am confused that there is no error returned.

Any tips would be a great help.

Regards,
Alan.


I think that I've been using the wrong function. WriteProfileString is
for writing to ini files and not to the registry. Is this true? My
research goes on.

Regards.


Nov 13 '05 #3
On Fri, 03 Jun 2005 13:43:05 -0400, Alan Searle
<aj*******@xxxxyahoo.com> wrote:

I would like to write values to the registry and am having problems with
a very simple block of code. Here it is ...

--------------------------------------------------------
Option Compare Database
Option Explicit

Private Declare Function WriteProfileString _
Lib "kernel32" Alias "WriteProfileStringA" _
(ByVal lpszSection As String, _
ByVal lpszKeyName As String, _
ByVal lpszString As String) As Long

Public Function UpdateReg() As Integer

Dim RetVal As Integer

RetVal = WriteProfileString("\HKEY_CURRENT_USER\Software\AD OBE\Acrobat
PDFWriter", "szTitle", "mynewtitle")

If RetVal <> 1 Then
MsgBox "Problem"
Else
MsgBox "success"
End If

End Function
---------------------------------------------------------

I need to write the string "mynewtitle" to the entry "szTitle" in the
key "Acrobat PDFWriter" and although my call to "WriteProfileString"
reports 'success' (returns 1), the code fails to write the value in.

However, I can write/change entries in the registry manually with
regedit so I assume my permissions are OK.

I find it very strange that the code is not returning an error (rather
than reporting success) and I am hoping that someone can take a quick
look at my code and can tell me if there is a simple error somewhere?

I am running this on an NT 4.0 (server), with the VBA code in MSAccess
97. And I have tried both with the full path of the key (as above) and
with a simple key: "Acrobat PDFWriter".

Maybe there is something wrong with the API call? With the declaration
of the call? Or with Kernal32? But I am not sure how to check/diagnose
this. And am confused that there is no error returned.

Any tips would be a great help.

Regards,
Alan.


Hi
I have no experience of using WriteProfileString but isn't this for
16-bit compatibilty? The string arguments are supposed to map to
section names in the ini file in a complicated manner, eg see
http://msdn.microsoft.com/library/de...filestring.asp

To write directly to the registry if you are confident enough, see
http://www.arcatapet.net/vbregset.cfm
One normally backs up the registry or sets a system restore point
before testing programs which do this sort of thing.

or to see how it all works read some of the registry routines in Randy
Birch's site
http://vbnet.mvps.org/
(Note this is vb, NOT vb.net)

another way would be to make a .REG file and shell out to regedit.
David
Nov 13 '05 #4
Yes.

There are loads of registry writing modules on the web, have a look at the
code in http://vb.mvps.org/samples/code/RegSettings.zip

for example

--
Terry Kreft
MVP Microsoft Access
"Alan Searle" <aj*******@xxxxyahoo.com> wrote in message
news:d7**********@newsreader3.netcologne.de...
Alan Searle wrote:

I would like to write values to the registry and am having problems with
a very simple block of code. Here it is ...

--------------------------------------------------------
Option Compare Database
Option Explicit

Private Declare Function WriteProfileString _
Lib "kernel32" Alias "WriteProfileStringA" _
(ByVal lpszSection As String, _
ByVal lpszKeyName As String, _
ByVal lpszString As String) As Long

Public Function UpdateReg() As Integer

Dim RetVal As Integer

RetVal = WriteProfileString("\HKEY_CURRENT_USER\Software\AD OBE\Acrobat
PDFWriter", "szTitle", "mynewtitle")

If RetVal <> 1 Then
MsgBox "Problem"
Else
MsgBox "success"
End If

End Function
---------------------------------------------------------

I need to write the string "mynewtitle" to the entry "szTitle" in the
key "Acrobat PDFWriter" and although my call to "WriteProfileString"
reports 'success' (returns 1), the code fails to write the value in.

However, I can write/change entries in the registry manually with
regedit so I assume my permissions are OK.

I find it very strange that the code is not returning an error (rather
than reporting success) and I am hoping that someone can take a quick
look at my code and can tell me if there is a simple error somewhere?

I am running this on an NT 4.0 (server), with the VBA code in MSAccess
97. And I have tried both with the full path of the key (as above) and
with a simple key: "Acrobat PDFWriter".

Maybe there is something wrong with the API call? With the declaration
of the call? Or with Kernal32? But I am not sure how to check/diagnose
this. And am confused that there is no error returned.

Any tips would be a great help.

Regards,
Alan.


I think that I've been using the wrong function. WriteProfileString is
for writing to ini files and not to the registry. Is this true? My
research goes on.

Regards.

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rohit Santhanam | last post by:
As I am reading the .NET documentation, I get the feeling that Microsoft is trying to get rid of the registry. My understanding is that an application built using .NET does not use the registry...
0
by: glenn | last post by:
I am trying to write to the registry and the objects that are suppose to be handling this function are not working. Here is what is happening. I am issuing the following commands: RegistryKey...
2
by: glenn | last post by:
I am trying to write to the registry and the objects that are suppose to be handling this function are not working. Here is what is happening. I am issuing the following commands: RegistryKey...
2
by: LCD | last post by:
Here is what I want to do: Presently in my registry I have: (Default) = "C:\Program Files\myApp" and this value is scattered all over registry in several keys and subkeys. I wouldlike to...
5
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I...
3
by: Sreppohcdoow | last post by:
I have a simple tool that I create that stores some settings in the Registry... however, if the user running it doesn't have Admin priveleges on the machine, the app fails when trying to write to...
1
by: Chris Mullins | last post by:
I need to write to the 32-bit registry, and need to do so from a 64-bit MSI. It never occurred to me that this would be difficult... I have an application that installs some 64-bit binaries for...
14
by: Newbie Coder | last post by:
Hi all, VB.NET 2003 ONLY PLEASE I have a registry key (HKCU\Software\Newbie\SomeKey) of type string which holds an XML string as follows: <root formID="preferencesform" lang="english" ...
1
by: projectVBA | last post by:
Hi , I wrote some add in for PowerPoint and i'm trying to find an automatic way to load it every time PowerPoint starts. I found Microsoft Code example (see below ) BUT the problem is : I can't...
2
by: J.K. Baltzersen | last post by:
Dear all, I have a counter in my Windows registry. Is there any way of ensuring that it is updated by one process/thread at a time only. One way of updating is retrieving the counter,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.