Problem writing to NT registry using WSHShell.RegWrite

Posted on 2001-07-24
Last Modified: 2010-05-18
Hi, I use the following function to read and write to the system registry, and apply default values if requried. I need to access HKEY_LOCAL_MACHINE rather than USER for an NT application therefore could not use GetSetting etc.

This function works fine on Win2000 and all the Win98 machines I have tested it on. HOWEVER!!! on the clients pesky Windows NT machine there is NO entries in the registry !!! My function normally creates a node called OmniTerm but with this NT machine there is no entry. Very confused ! Yes, I am logged onto the machine as an administrator at both install and run time.

Any ideas ?


Public Function Registry(VariableName As String, VariableValue As Variant, Writing As Boolean) As Variant
On Error Resume Next
Dim WSHShell As Object
Set WSHShell = CreateObject("WScript.Shell")
If Writing = True Then
'Write values:
  WSHShell.RegWrite "HKEY_LOCAL_MACHINE\Software\OmniTerm\"_ & Trim(VariableName), VariableValue
  Registry = ""
'Read values:
 Registry = WSHShell.RegRead("HKEY_LOCAL_MACHINE\Software\OmniTerm\" & Trim_(VariableName))
' Set defaults, can be passed from calling code
  If Registry = Empty Then_ WSHShell.RegWrite "HKEY_LOCAL_MACHINE\Software\OmniTerm\"_ & VariableName, VariableValue: Registry = VariableValue
End If
Set WSHShell = Nothing
If Err Then Debug.Print Error$ 'Do not report, always_ err's if registry empty
End Function
Question by:nvms
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
  • 3
  • 2
  • 2

Accepted Solution

Dave_Greene earned 100 total points
ID: 6313224
How about giving this a shot, much easier :)

Dim sValue As String
dim KeyFound  as Boolean

Dim Reg As New Registry

Result = Reg.UpdateKey (HKEY_LOCAL_MACHINE, "Software\OmniTerm", "VariableName", "NEW VALUE")

sValue = ""

KeyFound = Reg.GetKeyValue(HKEY_LOCAL_MACHINE, _
  "Software\OmniTerm", "VariableName", sValue)

MsgBox sValue

Author Comment

ID: 6315470
Looks good so far except that:

Dim Reg As New Registry

must be referring to a class object or something because VB gives a large shrug when the line is reached...

Cheers !


Expert Comment

ID: 6315476
what version of vb are you running?
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.


Author Comment

ID: 6320353
6.0 ... I was at the clients yesterday and noticed that wscript.exe was not in c:\winnt\system32 as it is on my W2K machine. Simply copying the file onto their machine made no difference. I wonder if it needed to be registered somehow ? Anyway, sort of worked around by using the GetSetting SaveSetting commands but now the registry settings change between users which is a main in the arm.



Expert Comment

ID: 6743533
There has been no activity in this question in quite some time, and it looks like it has been abandoned. As part of our ongoing mission to clean up the topic areas, a Moderator will finalize this question within the next seven (7) days. At that time, either I or one of the other Moderators will force/accept the comment of Dave_Greene.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER. If you have further comments on this question or the recommendation, please leave them here.


Community Support Moderator
Experts Exchange

Expert Comment

ID: 6759799

You last logged in on 1/14/2002, and you have disregarded our requests for you to clean up your open questions. I am therefore force/accepting a comment to close this question.

Community Support Moderator
Experts Exchange

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

695 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