Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem writing to NT registry using WSHShell.RegWrite

Posted on 2001-07-24
7
Medium Priority
?
289 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Industry Leaders: 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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

971 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