By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Registry Writing

P: n/a

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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.