Solved

Problem writing to NT registry using WSHShell.RegWrite

Posted on 2001-07-24
7
281 Views
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 ?

Stewart

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 = ""
Else
'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
0
Comment
Question by:nvms
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
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
0
 

Author Comment

by:nvms
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 !

Stewart
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6315476
what version of vb are you running?
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:nvms
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.

Cheers

Stewart
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6729042
0
 
LVL 5

Expert Comment

by:Netminder
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.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6759799
nvms,

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.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

777 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