Solved

Problem writing to NT registry using WSHShell.RegWrite

Posted on 2001-07-24
7
275 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
Comment Utility
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
Comment Utility
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
Comment Utility
what version of vb are you running?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:nvms
Comment Utility
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
Comment Utility
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now